ci: harden publish workflow against non-fast-forward bump push

Merged
SW
4mo ago
+10-4

Why

The Publish to npm workflow failed twice on cli#24's release:

  1. First run: bad NPM_TOKEN → E404 at pnpm publish (token since fixed).
  2. Re-run: failed before publish, at the version-bump push —
    ! [rejected] main -> main (fetch first). The re-run checked out the
    original pre-bump SHA, and git push was non-fast-forward because the first
    run had already pushed the 0.1.14 bump to main.

Net: main is at 0.1.14 but npm is still 0.1.13 (never published).

Fix

  • checkout with ref: main + fetch-depth: 0 — the job always operates on the latest main tip (re-runs stop using a stale SHA) with full history for the rebase.
  • git pull --rebase origin main before the bump — race safety net so the push is always fast-forward.
  • git push origin HEAD:main (explicit) + capture the new version straight from npm version output (removes the node -p require()).
  • workflow_dispatch trigger so a publish can be re-kicked from the Actions UI without pushing a commit.

Effect on merge

Merging this is itself a push to main → triggers a fresh run from the current tip (0.1.14) → bumps to 0.1.15 → publishes with the (now valid) token. After it goes green, npm view @recoupable/cli version should show 0.1.15 with the emails command rename.

Gate reminder (chat#1815): don't promote api#711 to prod (api#715) until this publishes.

🤖 Generated with Claude Code


Summary by cubic

Hardened the npm publish workflow so the version-bump push is always fast-forward, even on re-runs or races. The job now operates from the latest main and supports manual runs.

  • Bug Fixes

    • Checkout with ref: main and fetch-depth: 0 to always use the latest main with full history.
    • Rebase before bumping: git pull --rebase origin main to keep the push fast-forward.
    • Push explicitly with git push origin HEAD:main.
    • Read the new version from npm version output (drops the node -p require()).
  • New Features

    • Add workflow_dispatch to trigger a publish from the Actions UI without a new commit.