mirror of
https://github.com/kunkunsh/kunkun-ext-jwt.git
synced 2025-03-31 09:06:42 +00:00
fix: improve npm publish workflow to check for existing package version before publishing
This commit is contained in:
parent
8376f2acf8
commit
3cde72d7f8
28
.github/workflows/npm-publish.yml
vendored
28
.github/workflows/npm-publish.yml
vendored
@ -1,6 +1,3 @@
|
||||
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
||||
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
||||
|
||||
name: NPM Package Publish
|
||||
|
||||
on:
|
||||
@ -25,21 +22,16 @@ jobs:
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
- run: bun install
|
||||
- run: bun run build
|
||||
- run: |
|
||||
bunx kksh@latest verify --publish
|
||||
- run: bunx kksh@latest verify --publish
|
||||
- name: Check if version is already published
|
||||
run: |
|
||||
PACKAGE_VERSION=$(node -p "require('./package.json').version")
|
||||
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
|
||||
npm view $PACKAGE_NAME@$PACKAGE_VERSION
|
||||
continue-on-error: true
|
||||
id: check_version
|
||||
- name: Publish
|
||||
if: steps.check_version.outcome != 'success'
|
||||
run: npm publish --provenance --access public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user