Skip to content

Commit e9b450b

Browse files
committed
ci: skip npm publish if version already exists
Prevents CI failure when version was already published locally.
1 parent 25df628 commit e9b450b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

.github/workflows/publish.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ jobs:
2626
- name: Verify package
2727
run: npm pack --dry-run
2828

29-
- run: npm publish --provenance --access public
29+
- name: Check if version already published
30+
id: check
31+
run: |
32+
PKG_NAME=$(node -p "require('./package.json').name")
33+
PKG_VERSION=$(node -p "require('./package.json').version")
34+
if npm view "${PKG_NAME}@${PKG_VERSION}" version 2>/dev/null; then
35+
echo "already_published=true" >> "$GITHUB_OUTPUT"
36+
echo "⚠️ ${PKG_NAME}@${PKG_VERSION} already published, skipping"
37+
else
38+
echo "already_published=false" >> "$GITHUB_OUTPUT"
39+
fi
40+
41+
- name: Publish to npm
42+
if: steps.check.outputs.already_published != 'true'
43+
run: npm publish --provenance --access public
3044
env:
3145
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)