-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: setup semantic release for tag automation
Signed-off-by: David van der Spek <[email protected]>
- Loading branch information
Showing
4 changed files
with
92 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,14 @@ name: Build Notebook Images | |
|
||
on: | ||
push: | ||
branches: [ master ] | ||
tags: | ||
- 'v*.*.*' | ||
branches: [ main ] | ||
# tags: | ||
# - 'v*.*.*' | ||
pull_request: | ||
branches: | ||
- 'master' | ||
- 'main' | ||
|
||
jobs: | ||
jobs: | ||
build-matrix: | ||
name: Create Build Matrix | ||
runs-on: ubuntu-latest | ||
|
@@ -20,32 +20,20 @@ jobs: | |
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 # No shallow clone, we need all history | ||
- | ||
name: Bump version and push tag | ||
if: github.event_name != 'pull_request' | ||
id: tag_version | ||
uses: mathieudutour/[email protected] | ||
token: ${{ secrets.PLURAL_BOT_PAT }} | ||
- name: 'Setup Node' | ||
uses: actions/setup-node@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
- | ||
name: Create a GitHub release | ||
if: github.event_name != 'pull_request' | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ steps.tag_version.outputs.new_tag }} | ||
release_name: Release ${{ steps.tag_version.outputs.new_tag }} | ||
body: ${{ steps.tag_version.outputs.changelog }} | ||
node-version: 18.12.1 | ||
- name: Install Semantic Release Plus | ||
run: npm install -g semantic-release-plus @semantic-release/exec | ||
- name: generate matrix | ||
id: generate-matrix | ||
env: | ||
RELEASE: ${{ steps.tag_version.outputs.new_tag }} | ||
# run: echo "::set-output name=matrix::{\"include\":[$(for changed_folder in $(dirname $(git diff --name-only ${{ github.event.before }}..${{ github.event.after }}) | sort -u); do find $changed_folder -name "*Dockerfile"; done | sed 's/^\|$/"/g'|paste -sd, -)]}" | ||
GITHUB_TOKEN: ${{ secrets.PLURAL_BOT_PAT }} | ||
run: | | ||
if [ -z "${RELEASE}" ]; | ||
if [ ${{ github.event_name }} == 'pull_request' ]; | ||
then | ||
RELEASE="pr" | ||
CHANGED_DIRS=$(git diff-tree --no-commit-id --name-only -r ${{ github.event.pull_request.head.sha }} | xargs -I {} dirname {}) | ||
else | ||
CHANGED_DIRS=$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | xargs -I {} dirname {}) | ||
|
@@ -59,14 +47,28 @@ jobs: | |
fi | ||
fi | ||
echo "${CHANGED_DIRS}" | ||
CONTAINER_FOLDERS=$(for CHANGED_DIR in ${CHANGED_DIRS}; do echo ${CHANGED_DIR} | awk -F "/" '{print $1}'; done | sort -u) | ||
for CONTAINER_FOLDER in ${CONTAINER_FOLDERS}; do | ||
if [[ "${CONTAINER_FOLDER}" != "."* ]]; then | ||
APP_NAME="${CONTAINER_FOLDER}" semantic-release | ||
if [ -f "release_version" ]; then | ||
mv release_version ${CONTAINER_FOLDER}/release_version | ||
else | ||
echo "pr" > ${CONTAINER_FOLDER}/release_version | ||
fi | ||
fi | ||
done | ||
DOCKERFILES=$(for CHANGED_DIR in ${CHANGED_DIRS}; do find ${CHANGED_DIR} -name "*Dockerfile"; done | sort -u) | ||
echo "${DOCKERFILES}" | ||
MATRIX_PROJECTS_JSON="[" | ||
MATRIX_INCLUDE_JSON="[" | ||
for DOCKERFILE in ${DOCKERFILES}; do | ||
DIR=$(dirname ${DOCKERFILE}) | ||
RELEASE=$(cat ${DIR}/release_version) | ||
if [[ "$(basename ${DOCKERFILE})" == *"cuda"* ]] | ||
then | ||
then | ||
MATRIX_PROJECTS_JSON+=$(sed 's/^/"/;s/$/"/' <<< "${DIR}"-cuda) | ||
PROJECT="${DIR}"-cuda | ||
else | ||
|
@@ -85,16 +87,16 @@ jobs: | |
MATRIX_PROJECTS_JSON+="]" | ||
MATRIX_JSON="{\"include\": ${MATRIX_INCLUDE_JSON}}" | ||
echo "${MATRIX_JSON}" | ||
CONTINUE_DOCKER_JOB="no" | ||
if [[ "${MATRIX_PROJECTS_JSON}" != "[]" ]]; then | ||
CONTINUE_DOCKER_JOB="yes" | ||
fi | ||
echo "${CONTINUE_DOCKER_JOB}" | ||
echo "::set-output name=continue::${CONTINUE_DOCKER_JOB}" | ||
echo "::set-output name=matrix::${MATRIX_JSON}" | ||
echo "continue=${CONTINUE_DOCKER_JOB}" >> $GITHUB_OUTPUT | ||
echo "matrix=${MATRIX_JSON}" >> $GITHUB_OUTPUT | ||
outputs: | ||
matrix: ${{ steps.generate-matrix.outputs.matrix }} | ||
continue: ${{ steps.generate-matrix.outputs.continue }} | ||
|
@@ -109,12 +111,6 @@ jobs: | |
- | ||
name: Checkout | ||
uses: actions/checkout@v2 | ||
- | ||
name: Get latest tag | ||
id: latest_tag | ||
uses: DavidSpek/[email protected] | ||
with: | ||
img: 'ghcr.io/pluralsh/kubeflow-notebooks-${{ matrix.project }}' | ||
- | ||
name: Docker meta | ||
id: meta | ||
|
@@ -127,7 +123,7 @@ jobs: | |
tags: | | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{raw}},value=${{ steps.latest_tag.outputs.new_v_patch }} | ||
type=semver,pattern={{raw}},value=${{ matrix.version }} | ||
type=sha | ||
- | ||
name: Set up QEMU | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: "Semantic PR" | ||
|
||
on: | ||
workflow_dispatch: | ||
# pull_request_target: | ||
# types: | ||
# - opened | ||
# - edited | ||
# - synchronize | ||
|
||
jobs: | ||
main: | ||
name: Validate PR title | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: amannn/action-semantic-pull-request@v5 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const name = process.env.APP_NAME; | ||
|
||
module.exports = { | ||
branches: ["main"], | ||
tagFormat: name + '-v${version}', | ||
plugins: [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/github", | ||
[ | ||
"@semantic-release/exec", | ||
{ | ||
"verifyReleaseCmd": "echo ${nextRelease.version} > release_version" | ||
} | ||
] | ||
], | ||
commitPaths: [ | ||
name, | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters