Skip to content

Commit 6ec7547

Browse files
committed
Update publish.yml
1 parent b992d36 commit 6ec7547

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,35 @@ jobs:
3939
- name: Build
4040
run: pnpm build
4141

42+
- name: Preflight publish checks
43+
id: preflight
44+
shell: bash
45+
env:
46+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
47+
run: |
48+
set -euo pipefail
49+
if [ -z "${NODE_AUTH_TOKEN:-}" ]; then
50+
echo "NPM_TOKEN is not configured."
51+
exit 1
52+
fi
53+
npm whoami >/dev/null
54+
55+
PKG_NAME="$(node -p "require('./package.json').name")"
56+
PKG_VERSION="$(node -p "require('./package.json').version")"
57+
echo "package_name=${PKG_NAME}" >> "$GITHUB_OUTPUT"
58+
echo "package_version=${PKG_VERSION}" >> "$GITHUB_OUTPUT"
59+
60+
if npm view "${PKG_NAME}@${PKG_VERSION}" version >/dev/null 2>&1; then
61+
echo "Version ${PKG_NAME}@${PKG_VERSION} already exists on npm. Skipping publish."
62+
echo "should_publish=false" >> "$GITHUB_OUTPUT"
63+
exit 0
64+
fi
65+
66+
echo "Version ${PKG_NAME}@${PKG_VERSION} is not published yet."
67+
echo "should_publish=true" >> "$GITHUB_OUTPUT"
68+
4269
- name: Publish
70+
if: steps.preflight.outputs.should_publish == 'true'
4371
run: npm publish --provenance --access public
4472
env:
4573
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)