File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 }}
You can’t perform that action at this time.
0 commit comments