From 67e8f5b981a59c85f452e185c3f036ed2f12f40e Mon Sep 17 00:00:00 2001 From: David van der Spek Date: Tue, 19 Sep 2023 14:08:11 +0200 Subject: [PATCH] ci: setup semantic release for tag automation Signed-off-by: David van der Spek --- .github/workflows/build-all.yml | 68 ++++++++++++++---------------- .github/workflows/semantic-pr.yaml | 18 ++++++++ release.config.js | 20 +++++++++ renovate.json | 24 ++++++++++- 4 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/semantic-pr.yaml create mode 100644 release.config.js diff --git a/.github/workflows/build-all.yml b/.github/workflows/build-all.yml index f7bc4d20..3e131722 100644 --- a/.github/workflows/build-all.yml +++ b/.github/workflows/build-all.yml @@ -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/github-tag-action@v6.0 + 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,7 +87,7 @@ 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" @@ -93,8 +95,8 @@ jobs: 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/gha-get-docker-hub-tags@0.1.15 - 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 diff --git a/.github/workflows/semantic-pr.yaml b/.github/workflows/semantic-pr.yaml new file mode 100644 index 00000000..370bf5ea --- /dev/null +++ b/.github/workflows/semantic-pr.yaml @@ -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 }} diff --git a/release.config.js b/release.config.js new file mode 100644 index 00000000..9fd0cb0b --- /dev/null +++ b/release.config.js @@ -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, + ] +}; diff --git a/renovate.json b/renovate.json index 74da9893..cb66d308 100644 --- a/renovate.json +++ b/renovate.json @@ -2,7 +2,9 @@ "extends": [ "config:base", ":dependencyDashboard", + ":gitSignOff", ":prHourlyLimit4", + ":semanticCommits", ":prConcurrentLimit10" ], "schedule": [ @@ -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", @@ -43,9 +53,19 @@ "matchPackagePatterns": ["^torch*[a-z-].*"], "groupName": "pytorch", "versioning": "regex:^(?\\d+)\\.(?\\d+)\\.(?\\d+)(?[^.-]+)?(-(?.*))?$" + }, + { + "description": "Automerge everything", + "matchUpdateTypes": ["major", "minor", "patch"], + "automerge": true, + "automergeType": "pr", + "platformAutomerge": true } ], - "automerge": true, + "labels": [ + "dependencies" + ], + "separateMinorPatch": true, "dependencyDashboardApproval": true, "regexManagers": [ {