Skip to content

Commit

Permalink
ci: setup semantic release for tag automation
Browse files Browse the repository at this point in the history
Signed-off-by: David van der Spek <[email protected]>
  • Loading branch information
davidspek committed Sep 19, 2023
1 parent 0da3e05 commit 67e8f5b
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 38 deletions.
68 changes: 32 additions & 36 deletions .github/workflows/build-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {})
Expand All @@ -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
Expand All @@ -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 }}
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/semantic-pr.yaml
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 }}
20 changes: 20 additions & 0 deletions release.config.js
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,
]
};
24 changes: 22 additions & 2 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"extends": [
"config:base",
":dependencyDashboard",
":gitSignOff",
":prHourlyLimit4",
":semanticCommits",
":prConcurrentLimit10"
],
"schedule": [
Expand All @@ -16,7 +18,15 @@
"matchUpdateTypes": [
"major"
],
"enabled": true
"enabled": true,
"commitBody": "BREAKING CHANGE: major release of {{depName}}"
},
{
"matchDatasources": [
"docker"
],
"semanticCommitScope": "{{baseDir}}",
"semanticCommitType": "{{#if isPatch}}fix{{else}}feat{{/if}}"
},
{
"description": "Group Conda and Miniforge",
Expand All @@ -43,9 +53,19 @@
"matchPackagePatterns": ["^torch*[a-z-].*"],
"groupName": "pytorch",
"versioning": "regex:^(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(?<prerelease>[^.-]+)?(-(?<compatibility>.*))?$"
},
{
"description": "Automerge everything",
"matchUpdateTypes": ["major", "minor", "patch"],
"automerge": true,
"automergeType": "pr",
"platformAutomerge": true
}
],
"automerge": true,
"labels": [
"dependencies"
],
"separateMinorPatch": true,
"dependencyDashboardApproval": true,
"regexManagers": [
{
Expand Down

0 comments on commit 67e8f5b

Please sign in to comment.