From 602d3c8dbfce022192a67d06f42de9e12293aa41 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 22:15:14 +0000 Subject: [PATCH 1/2] Release through a bump PR so main can stay PR-only The main ruleset now requires pull requests, which rejected the bump action's direct push (GH013) and blocked the 3.0.0 release. The release workflow now opens a PR with the package.json bump, merges it with [skip ci], then tags and releases the merge commit. package.json in the repo stays in step with the released version. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QhgcNyPGK62bg5XGGZhpkx --- .github/workflows/release.yml | 135 ++++++++++++++++++++++++++-------- 1 file changed, 105 insertions(+), 30 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 363cc0e..3129115 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,17 @@ -name: "Bump Version and Release" +name: "Release" + +# After every green CI run on main, bump the version through a pull request +# (main only accepts pull requests), merge it, then tag and release that commit. +# +# Version bump comes from the commit messages since the latest v* tag: +# "major"/"breaking" -> major, "minor"/"feat"/"feature" -> minor, else patch. +# +# The bump PR's merge commit carries [skip ci], so it doesn't start another +# CI -> release cycle. The release (created with RELEASE_TOKEN so other +# workflows fire) triggers npm-publish.yml. +# +# RELEASE_TOKEN needs contents + pull-requests write on this repo. If the main +# ruleset ever requires approvals or status checks, the bump PR will wait for them. on: workflow_run: @@ -8,54 +21,116 @@ on: branches: - main +concurrency: + group: release + cancel-in-progress: false + jobs: - bump-version: - name: "Bump Version on main" + release: + name: "Bump, tag and release" runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} + if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' }} steps: - - name: "Checkout source code" + - name: "Checkout the commit CI tested" uses: "actions/checkout@v4" with: - ref: main + ref: ${{ github.event.workflow_run.head_sha }} + fetch-depth: 0 + token: ${{ secrets.RELEASE_TOKEN }} - name: "Setup Node.js" uses: "actions/setup-node@v4" with: node-version: "24" - - name: "cat package.json" - run: cat ./package.json + - name: "Work out the next version" + id: version + run: | + set -euo pipefail + if [ -n "$(git tag --points-at HEAD --list 'v[0-9]*')" ]; then + echo "HEAD is already tagged; nothing to release." + exit 0 + fi - - name: "Automated Version Bump" - id: version-bump - uses: "phips28/gh-action-bump-version@v11.0.7" - with: - tag-prefix: "v" - major-wording: "major,Major,breaking,Breaking" - minor-wording: "minor,Minor,feat,Feat,feature,Feature" - patch-wording: "patch,Patch,fix,Fix,fixes,Fixes" - rc-wording: "rc,pre,beta,alpha" # For pre-releases - commit-message: "ci: bump version to {{version}} [skip ci]" # Skips re-triggering - push: true # Pushes the commit/tag back to main - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + last_tag=$(git tag --list 'v[0-9]*' --sort=-v:refname | head -n 1) + if [ -z "$last_tag" ]; then + last_tag="v$(node -p "require('./package.json').version")" + range="HEAD" + else + range="$last_tag..HEAD" + fi + + # Ignore earlier release commits when choosing the bump + messages=$(git log --format=%B "$range" | grep -v '^ci: release v' || true) + if [ -z "$(tr -d '[:space:]' <<<"$messages")" ]; then + echo "No changes since $last_tag; nothing to release." + exit 0 + fi - - name: "cat package.json" - run: cat ./package.json + if grep -qE '\b([Mm]ajor|[Bb]reaking)\b' <<<"$messages"; then + bump=major + elif grep -qE '\b([Mm]inor|[Ff]eat|[Ff]eature)\b' <<<"$messages"; then + bump=minor + else + bump=patch + fi - - name: "Output Step" + IFS=. read -r major minor patch <<<"${last_tag#v}" + case "$bump" in + major) major=$((major + 1)); minor=0; patch=0 ;; + minor) minor=$((minor + 1)); patch=0 ;; + patch) patch=$((patch + 1)) ;; + esac + + version="$major.$minor.$patch" + echo "$last_tag -> v$version ($bump)" + echo "version=$version" >> "$GITHUB_OUTPUT" + + - name: "Open and merge the version bump PR" + id: bump + if: ${{ steps.version.outputs.version }} env: - NEW_TAG: ${{ steps.version-bump.outputs.newTag }} - run: echo "new tag $NEW_TAG" + GH_TOKEN: ${{ secrets.RELEASE_TOKEN }} + VERSION: ${{ steps.version.outputs.version }} + run: | + set -euo pipefail + branch="release/v$VERSION" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + git switch -c "$branch" + npm version "$VERSION" --no-git-tag-version + git commit -am "ci: release v$VERSION [skip ci]" + git push origin "$branch" + + gh pr create --base main --head "$branch" \ + --title "Release v$VERSION" \ + --body "Automated version bump to v$VERSION after CI passed on main." + # GitHub computes mergeability asynchronously, so retry briefly + for attempt in 1 2 3 4 5 6; do + if gh pr merge "$branch" --merge --delete-branch \ + --subject "ci: release v$VERSION [skip ci]"; then + break + fi + if [ "$attempt" = 6 ]; then + echo "Could not merge the release PR; see the error above." >&2 + exit 1 + fi + sleep 10 + done + + sha=$(gh pr view "$branch" --json mergeCommit --jq .mergeCommit.oid) + echo "Merged as $sha" + echo "sha=$sha" >> "$GITHUB_OUTPUT" - - name: "Create GitHub Release" - if: ${{ steps.version-bump.outputs.newTag }} + - name: "Create tag and GitHub release" + if: ${{ steps.bump.outputs.sha }} uses: "softprops/action-gh-release@v2" with: - tag_name: ${{ steps.version-bump.outputs.newTag }} - name: Release ${{ steps.version-bump.outputs.newTag }} + tag_name: v${{ steps.version.outputs.version }} + target_commitish: ${{ steps.bump.outputs.sha }} + name: Release v${{ steps.version.outputs.version }} generate_release_notes: true env: GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} From 1faa8d7e6ea3fbe136aa9e745ee9eb41264383e4 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 22:17:19 +0000 Subject: [PATCH 2/2] Release: bump from latest main and survive re-runs - Compute the version from main rather than the commit whose CI finished, so the bump covers every commit the release PR actually merges. - Force-push the bot's release branch and reuse an open release PR, so a re-run after a failed merge isn't blocked by the earlier attempt. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QhgcNyPGK62bg5XGGZhpkx --- .github/workflows/release.yml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3129115..6d3c96f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,10 +32,13 @@ jobs: if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' }} steps: - - name: "Checkout the commit CI tested" + # Use the latest main, not just the commit whose CI finished: if more PRs + # landed meanwhile, the bump must account for every commit it releases. + # Their own CI runs will then find nothing new to release. + - name: "Checkout main" uses: "actions/checkout@v4" with: - ref: ${{ github.event.workflow_run.head_sha }} + ref: main fetch-depth: 0 token: ${{ secrets.RELEASE_TOKEN }} @@ -99,14 +102,17 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git switch -c "$branch" + git switch -C "$branch" npm version "$VERSION" --no-git-tag-version git commit -am "ci: release v$VERSION [skip ci]" - git push origin "$branch" + # Force: a re-run after a failed attempt replaces the bot's own branch + git push --force origin "$branch" - gh pr create --base main --head "$branch" \ - --title "Release v$VERSION" \ - --body "Automated version bump to v$VERSION after CI passed on main." + if [ "$(gh pr view "$branch" --json state --jq .state 2>/dev/null || true)" != "OPEN" ]; then + gh pr create --base main --head "$branch" \ + --title "Release v$VERSION" \ + --body "Automated version bump to v$VERSION after CI passed on main." + fi # GitHub computes mergeability asynchronously, so retry briefly for attempt in 1 2 3 4 5 6; do if gh pr merge "$branch" --merge --delete-branch \