From d81ccfe7cf8dc62e4d2f2b88fe6170fbe29b1a90 Mon Sep 17 00:00:00 2001 From: Mads Hvelplund Date: Sun, 25 Oct 2026 10:09:18 +0100 Subject: [PATCH] ci: bump the version and tag with commitizen On every push to main, a Release workflow runs CI and then cz bump, which commits the new version and pushes it with a vX.Y.Z tag using a GitHub App token. CI no longer runs on main pushes itself; release.yml calls it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01K2ffjZ98kNMDjtSLJKwF2t --- .github/workflows/ci.yml | 4 +- .github/workflows/release.yml | 73 +++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c63cec0..6caf004 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,10 @@ name: CI +# Pushes to main run this through release.yml, before the version bump. on: - push: - branches: [main] pull_request: workflow_dispatch: + workflow_call: permissions: contents: read diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..44c0572 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,73 @@ +name: Release + +# On every push to main: run CI, then let commitizen bump the version from the +# Conventional Commits since the last tag. A bump commits the new version +# (.cz.toml, mise.toml pins, CHANGELOG.md) and pushes it with a `vX.Y.Z` tag. +# Commits that release nothing (docs, ci, chore, ...) leave main untouched. +# +# The push uses a token minted from a GitHub App, so it can get past branch +# protection and triggers workflows for the bump commit. The App's client ID is +# the RELEASE_APP_CLIENT_ID variable and its private key the +# RELEASE_APP_PRIVATE_KEY secret. +on: + push: + branches: [main] + +permissions: + contents: read + +# Bumps must run one at a time, in push order. +concurrency: + group: release + cancel-in-progress: false + +jobs: + ci: + uses: ./.github/workflows/ci.yml + + bump: + needs: ci + # The bump commit itself runs CI above, but must not bump again. + if: ${{ !startsWith(github.event.head_commit.message, 'bump:') }} + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.tag.outputs.tag }} + steps: + - uses: actions/create-github-app-token@v3 + id: app + with: + client-id: ${{ vars.RELEASE_APP_CLIENT_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-contents: write + - name: Bot identity + id: bot + env: + GH_TOKEN: ${{ steps.app.outputs.token }} + SLUG: ${{ steps.app.outputs.app-slug }} + run: | + id=$(gh api "/users/${SLUG}%5Bbot%5D" --jq .id) + echo "name=${SLUG}[bot]" >> "$GITHUB_OUTPUT" + echo "email=${id}+${SLUG}[bot]@users.noreply.github.com" >> "$GITHUB_OUTPUT" + - uses: actions/checkout@v7 + with: + token: ${{ steps.app.outputs.token }} + fetch-depth: 0 # all commits and tags since the last release + - uses: commitizen-tools/commitizen-action@0.27.1 + with: + github_token: ${{ steps.app.outputs.token }} + git_name: ${{ steps.bot.outputs.name }} + git_email: ${{ steps.bot.outputs.email }} + commitizen_version: 4.19.3 + changelog_increment_filename: release-notes.md + no_raise: '21' # NO_COMMITS_TO_BUMP: nothing to release + - name: Released tag + id: tag + run: | + if [ "$(git rev-parse HEAD)" != "$GITHUB_SHA" ]; then + echo "tag=$(git describe --tags --exact-match HEAD)" >> "$GITHUB_OUTPUT" + fi + - if: ${{ steps.tag.outputs.tag != '' }} + uses: actions/upload-artifact@v7 + with: + name: release-notes + path: release-notes.md