mirror of
https://github.com/kunkunsh/kunkun-ext-jwt.git
synced 2025-04-02 01:46:43 +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
|
name: NPM Package Publish
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@ -25,21 +22,16 @@ jobs:
|
|||||||
- uses: oven-sh/setup-bun@v2
|
- uses: oven-sh/setup-bun@v2
|
||||||
- run: bun install
|
- run: bun install
|
||||||
- run: bun run build
|
- run: bun run build
|
||||||
- run: |
|
- run: bunx kksh@latest verify --publish
|
||||||
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_NAME=$(jq -r '.name' package.json)
|
||||||
PACKAGE_VERSION=$(jq -r '.version' package.json)
|
npm view $PACKAGE_NAME@$PACKAGE_VERSION
|
||||||
|
continue-on-error: true
|
||||||
# Get the version from npm registry
|
id: check_version
|
||||||
REGISTRY_VERSION=$(npm show "$PACKAGE_NAME" version)
|
- name: Publish
|
||||||
|
if: steps.check_version.outcome != 'success'
|
||||||
# Compare versions
|
run: npm publish --provenance --access public
|
||||||
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:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user