Skip to content

Commit 63ff514

Browse files
authored
Attempt to fix NPM publish action failing if alr published (#4)
* Attempt to fix NPM publish action failing if alr published * chore: remove token from name+ver lookup step
1 parent 915519f commit 63ff514

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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
55
permissions:
66
contents: read
77
on:
@@ -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}}

0 commit comments

Comments
 (0)