File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
22# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
33
4- name : Publish NPM
4+ name : NPM Publish
55permissions :
66 contents : read
77on :
@@ -27,11 +27,30 @@ jobs:
2727 contents : write
2828 steps :
2929 - uses : actions/checkout@v4
30+
3031 - uses : actions/setup-node@v4
3132 with :
3233 node-version : 20
3334 registry-url : https://registry.npmjs.org/
35+
36+ - name : get pkg name & version
37+ id : pkg
38+ run : |
39+ echo "name=$(node -p \"require('./package.json').name\")" >> $GITHUB_OUTPUT
40+ echo "version=$(node -p \"require('./package.json').version\")" >> $GITHUB_OUTPUT
41+
3442 - run : npm ci
35- - run : npm publish
43+
44+ - name : publish if new version
45+ run : |
46+ PKG="${{ steps.pkg.outputs.name }}"
47+ VER="${{ steps.pkg.outputs.version }}"
48+ echo "Checking if $PKG@$VER exists..."
49+ if npm view "${PKG}@${VER}" >/dev/null 2>&1; then
50+ echo "Package version $VER already published — skipping publish (success)."
51+ else
52+ echo "Publishing $PKG@$VER..."
53+ npm publish
54+ fi
3655 env :
3756 NODE_AUTH_TOKEN : ${{secrets.npm_token}}
You can’t perform that action at this time.
0 commit comments