Skip to content

Commit f231ef2

Browse files
committed
fix(ci): gate npm publish on token/access checks
1 parent 8ad69ee commit f231ef2

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

.github/workflows/release.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,36 @@ jobs:
1717
if: github.event.workflow_run.conclusion == 'success'
1818
runs-on: ubuntu-latest
1919
steps:
20+
- name: Detect npm publish eligibility
21+
id: npm_gate
22+
shell: bash
23+
env:
24+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
25+
run: |
26+
set -euo pipefail
27+
echo "publish_npm=false" >> "$GITHUB_OUTPUT"
28+
29+
if [ -z "${NPM_TOKEN:-}" ]; then
30+
echo "::notice::NPM_TOKEN is empty; npm publish disabled for this run."
31+
exit 0
32+
fi
33+
34+
printf '%s\n' "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > "$HOME/.npmrc"
35+
36+
if ! npm whoami >/dev/null 2>&1; then
37+
echo "::warning::NPM_TOKEN is invalid/revoked; npm publish disabled for this run."
38+
exit 0
39+
fi
40+
41+
# Current workspace publishes @effect-template/* packages.
42+
if ! npm access ls-packages effect-template >/dev/null 2>&1; then
43+
echo "::warning::No publish access to npm scope 'effect-template'; npm publish disabled for this run."
44+
exit 0
45+
fi
46+
47+
echo "publish_npm=true" >> "$GITHUB_OUTPUT"
48+
echo "::notice::npm publish is enabled for this run."
49+
2050
- uses: ProverCoderAI/action-release@v1.0.17
2151
with:
2252
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -26,7 +56,7 @@ jobs:
2656
package_json_path: packages/app/package.json
2757
pnpm_filter: ./packages/app
2858
bump_type: patch
29-
publish_npm: false
59+
publish_npm: ${{ steps.npm_gate.outputs.publish_npm }}
3060
publish_github_packages: true
3161
skip_if_unchanged: true
3262
cancel_on_no_changes: true

0 commit comments

Comments
 (0)