From 050a3359b752443031d4ea2a990ce776c584f87b Mon Sep 17 00:00:00 2001 From: Sweets Sweetman Date: Thu, 25 Jun 2026 18:22:07 -0500 Subject: [PATCH] ci: harden publish workflow against non-fast-forward bump push MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The version-bump step commits + pushes to main from CI, which raced/failed on re-runs: a re-run checked out the original (pre-bump) SHA and its `git push` was rejected as non-fast-forward once main had moved ahead. - checkout `ref: main` + `fetch-depth: 0` so the job always works from the latest main tip (re-runs no longer use a stale SHA) with full history. - `git pull --rebase origin main` before bumping — race safety net. - `git push origin HEAD:main` (explicit) and capture the version straight from `npm version` output (drops the node -p require()). - add a `workflow_dispatch` trigger so a publish can be re-kicked from the Actions UI without pushing a commit. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/publish.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f92ac9f..6ab3c8d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,6 +3,7 @@ name: Publish to npm on: push: branches: [main] + workflow_dispatch: {} concurrency: group: publish @@ -17,6 +18,9 @@ jobs: - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} + # Full history + stay on the branch so the bump step can rebase + push. + fetch-depth: 0 + ref: main - uses: pnpm/action-setup@v4 with: @@ -33,11 +37,13 @@ jobs: run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - npm version patch --no-git-tag-version - VERSION=$(node -p "require('./package.json').version") + # Re-base onto the latest main first so a re-run or a race never hits a + # non-fast-forward push (the old failure mode). + git pull --rebase origin main + VERSION=$(npm version patch --no-git-tag-version) git add package.json - git commit -m "chore: bump version to $VERSION [skip ci]" - git push + git commit -m "chore: bump version to ${VERSION} [skip ci]" + git push origin HEAD:main - run: pnpm build