Skip to content

Commit a5cfe5d

Browse files
authored
ci(publish): atomic branch+tag push with race retry (#198)
--follow-tags pushes per-ref: when a merge train moves main mid-run, the HEAD:main push is rejected but the tag ref still lands, orphaning a release tag that fails every later run with 'tag already exists' (v0.43.25 and v0.43.27 today). --atomic makes branch+tag land together or not at all; a lost race resets to fresh main and retries.
1 parent 3092603 commit a5cfe5d

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

.github/workflows/publish.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,29 @@ jobs:
6262
# known-good release (>= 11.5.1 for OIDC). Revisit once a fixed 12.x ships.
6363
- run: npm install -g npm@11.18.0
6464

65-
- name: Bump patch, commit, tag, push
65+
# --atomic: branch + tag land together or not at all. --follow-tags is
66+
# per-ref — during a merge train the HEAD:main push gets rejected while
67+
# the tag ref is still accepted, orphaning a vX.Y.Z tag that poisons
68+
# every later release run ("fatal: tag already exists"). On a lost race,
69+
# undo the local bump and retry on fresh main; the newer merge's queued
70+
# run then no-ops via the already-published check.
71+
- name: Bump patch, commit, tag, push (atomic)
6672
run: |
6773
git config user.name "github-actions[bot]"
6874
git config user.email "github-actions[bot]@users.noreply.github.com"
69-
npm version patch -m "chore(release): %s [skip release]"
70-
git push origin HEAD:main --follow-tags
75+
for attempt in 1 2 3; do
76+
git fetch origin main
77+
git reset --hard origin/main
78+
npm version patch -m "chore(release): %s [skip release]"
79+
V=$(node -p "require('./package.json').version")
80+
if git push --atomic origin HEAD:main "refs/tags/v$V"; then
81+
exit 0
82+
fi
83+
echo "release push lost the race (attempt $attempt); retrying on fresh main"
84+
git tag -d "v$V"
85+
done
86+
echo "::error::release push lost the race 3 times — check for an orphaned tag"
87+
exit 1
7188
7289
- name: Publish to npm (skip if already published)
7390
run: |

0 commit comments

Comments
 (0)