Skip to content

Commit b8aae06

Browse files
committed
fix: handle race condition in release promote job
When a fresh non-prerelease is published, GitHub fires both 'published' and 'released' events simultaneously. The promote job races the deploy job and fails because the package isn't on npm yet. Add a retry loop (up to 5 min) so promote waits for the package to appear, while still failing loudly if it never does.
1 parent fbd6a57 commit b8aae06

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,20 @@ jobs:
2222
run: |
2323
VERSION=$(echo "$TAG_NAME" | sed 's/^v//')
2424
PACKAGE=$(node -p "require('./package.json').name")
25-
npm dist-tag add "$PACKAGE@$VERSION" latest
26-
echo "::notice title=Promoted $VERSION to latest::The latest tag now points to $VERSION (was edge-only)"
25+
26+
# Wait for version to be available on npm (handles race with deploy job)
27+
for i in $(seq 1 30); do
28+
if npm view "$PACKAGE@$VERSION" version &>/dev/null; then
29+
npm dist-tag add "$PACKAGE@$VERSION" latest
30+
echo "::notice title=Promoted $VERSION to latest::The latest tag now points to $VERSION"
31+
exit 0
32+
fi
33+
echo "Waiting for $PACKAGE@$VERSION on npm... (attempt $i/30)"
34+
sleep 10
35+
done
36+
37+
echo "::error title=Promotion failed::$PACKAGE@$VERSION not found on npm after 5 minutes"
38+
exit 1
2739
env:
2840
TAG_NAME: ${{ github.event.release.tag_name }}
2941
NODE_AUTH_TOKEN: ${{secrets.NPM_DEPLOY_TOKEN}}

0 commit comments

Comments
 (0)