mirror of
https://github.com/lancedikson/bowser
synced 2025-12-05 06:02:14 +00:00
ci(publish): add manual trigger and retry logic for npm publish
This commit is contained in:
parent
8ac2f6a1ec
commit
3c25806efe
43
.github/workflows/publish.yml
vendored
43
.github/workflows/publish.yml
vendored
@ -4,6 +4,13 @@ on:
|
|||||||
# This job runs when a new release is published
|
# This job runs when a new release is published
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published]
|
||||||
|
# Manual trigger with version input
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
version:
|
||||||
|
description: "Version to release (e.g., 2.12.1)"
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
@ -13,16 +20,44 @@ jobs:
|
|||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 12.16.3
|
node-version: 12.16.3
|
||||||
|
registry-url: "https://registry.npmjs.org"
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: ~/.npm
|
path: ~/.npm
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
|
||||||
# Store the name of the release
|
# Store the release version (from release tag or manual input)
|
||||||
# See https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
|
- name: Set release version
|
||||||
- run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||||
|
echo "RELEASE_VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
|
||||||
|
echo "Manual release triggered for version: ${{ github.event.inputs.version }}"
|
||||||
|
else
|
||||||
|
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
|
echo "Release triggered from tag: ${GITHUB_REF#refs/*/}"
|
||||||
|
fi
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm version $RELEASE_VERSION --no-git-tag-version
|
- run: npm version $RELEASE_VERSION --no-git-tag-version
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
- run: npm publish --access public
|
- name: Publish to npm with retry
|
||||||
|
run: |
|
||||||
|
max_attempts=5
|
||||||
|
attempt=1
|
||||||
|
while [ $attempt -le $max_attempts ]; do
|
||||||
|
echo "Attempt $attempt of $max_attempts..."
|
||||||
|
if npm publish --access public; then
|
||||||
|
echo "Successfully published!"
|
||||||
|
break
|
||||||
|
else
|
||||||
|
if [ $attempt -eq $max_attempts ]; then
|
||||||
|
echo "Failed to publish after $max_attempts attempts"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "Publish failed, waiting before retry..."
|
||||||
|
sleep_time=$((attempt * 30))
|
||||||
|
echo "Waiting ${sleep_time} seconds before retry..."
|
||||||
|
sleep $sleep_time
|
||||||
|
attempt=$((attempt + 1))
|
||||||
|
fi
|
||||||
|
done
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.BOWSER_NPM_PUBLISH_TOKEN }}
|
NODE_AUTH_TOKEN: ${{ secrets.BOWSER_NPM_PUBLISH_TOKEN }}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user