Skip to content

Commit

Permalink
ci: Enhance npm publish workflow to check for existing version in reg…
Browse files Browse the repository at this point in the history
…istry
  • Loading branch information
HuakunShen committed Jan 18, 2025
1 parent ce5a2b8 commit 274e1f0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ jobs:
with:
node-version: 22
registry-url: https://registry.npmjs.org/
- run: npm publish --provenance --access public
- run: |
PACKAGE_NAME=$(jq -r '.name' package.json)
PACKAGE_VERSION=$(jq -r '.version' package.json)
# Get the version from npm registry
REGISTRY_VERSION=$(npm show "$PACKAGE_NAME" version)
# Compare versions
if [ "$PACKAGE_VERSION" == "$REGISTRY_VERSION" ]; then
echo "Version $PACKAGE_VERSION already exists in the npm registry."
exit 0
else
echo "Version $PACKAGE_VERSION does not exist in the npm registry. Proceeding..."
npm publish --provenance --access public
fi
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

0 comments on commit 274e1f0

Please # to comment.