Skip to content

Commit 3c25806

Browse files
committed
ci(publish): add manual trigger and retry logic for npm publish
1 parent 8ac2f6a commit 3c25806

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

.github/workflows/publish.yml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ on:
44
# This job runs when a new release is published
55
release:
66
types: [published]
7+
# Manual trigger with version input
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: "Version to release (e.g., 2.12.1)"
12+
required: true
13+
type: string
714

815
jobs:
916
release:
@@ -13,16 +20,44 @@ jobs:
1320
- uses: actions/setup-node@v4
1421
with:
1522
node-version: 12.16.3
23+
registry-url: "https://registry.npmjs.org"
1624
- uses: actions/cache@v4
1725
with:
1826
path: ~/.npm
1927
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
20-
# Store the name of the release
21-
# See https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
22-
- run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
28+
# Store the release version (from release tag or manual input)
29+
- name: Set release version
30+
run: |
31+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
32+
echo "RELEASE_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
33+
echo "Manual release triggered for version: ${{ github.event.inputs.version }}"
34+
else
35+
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
36+
echo "Release triggered from tag: ${GITHUB_REF#refs/*/}"
37+
fi
2338
- run: npm ci
2439
- run: npm version $RELEASE_VERSION --no-git-tag-version
2540
- run: npm run build
26-
- run: npm publish --access public
41+
- name: Publish to npm with retry
42+
run: |
43+
max_attempts=5
44+
attempt=1
45+
while [ $attempt -le $max_attempts ]; do
46+
echo "Attempt $attempt of $max_attempts..."
47+
if npm publish --access public; then
48+
echo "Successfully published!"
49+
break
50+
else
51+
if [ $attempt -eq $max_attempts ]; then
52+
echo "Failed to publish after $max_attempts attempts"
53+
exit 1
54+
fi
55+
echo "Publish failed, waiting before retry..."
56+
sleep_time=$((attempt * 30))
57+
echo "Waiting ${sleep_time} seconds before retry..."
58+
sleep $sleep_time
59+
attempt=$((attempt + 1))
60+
fi
61+
done
2762
env:
2863
NODE_AUTH_TOKEN: ${{ secrets.BOWSER_NPM_PUBLISH_TOKEN }}

0 commit comments

Comments
 (0)