Skip to content

Commit aa48b40

Browse files
committed
fix(ci/release): fail when npm auth is missing
1 parent d3cf361 commit aa48b40

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

.github/workflows/release.yml

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,39 @@ permissions:
3030
statuses: write
3131

3232
jobs:
33+
npm-auth-check:
34+
name: Validate npm auth
35+
runs-on: ubuntu-latest
36+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
37+
timeout-minutes: 5
38+
env:
39+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
40+
steps:
41+
- name: Fail if NPM_TOKEN is missing
42+
run: |
43+
set -euo pipefail
44+
if [ -z "${NPM_TOKEN:-}" ]; then
45+
echo "NPM_TOKEN is required for release publishing" >&2
46+
exit 1
47+
fi
48+
49+
- name: Setup Node.js for auth check
50+
uses: actions/setup-node@v4
51+
with:
52+
node-version: '20'
53+
registry-url: 'https://registry.npmjs.org'
54+
55+
- name: Verify npm authentication
56+
env:
57+
NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }}
58+
run: |
59+
set -euo pipefail
60+
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
61+
npm whoami >/dev/null 2>&1 || { echo "npm auth failed (npm whoami). Ensure NPM_TOKEN is an npm automation token with publish rights to @just-every/*" >&2; exit 1; }
62+
3363
preflight-tests:
3464
name: Preflight Tests (Linux fast E2E)
65+
needs: [npm-auth-check]
3566
runs-on: ubuntu-24.04
3667
env:
3768
CARGO_TARGET_DIR: /mnt/cargo-target
@@ -128,6 +159,7 @@ jobs:
128159
129160
determine-version:
130161
name: Determine Version
162+
needs: [npm-auth-check]
131163
runs-on: ubuntu-latest
132164
outputs:
133165
version: ${{ steps.version.outputs.version }}
@@ -999,18 +1031,15 @@ jobs:
9991031
git push -u origin HEAD:main
10001032
10011033
- name: Publish per-target npm binary packages (last)
1002-
if: ${{ env.NPM_TOKEN != '' }}
10031034
env:
10041035
NODE_AUTH_TOKEN: ${{ env.NPM_TOKEN }}
10051036
shell: bash
10061037
run: |
10071038
set -euo pipefail
1008-
# If auth is missing (e.g., fork or expired token), skip gracefully to keep the
1009-
# release pipeline green while still exercising signing/packaging steps.
1010-
if ! npm whoami >/dev/null 2>&1; then
1011-
echo "npm auth unavailable; skipping per-target npm publish" >&2
1012-
exit 0
1013-
fi
1039+
config_path="${NPM_CONFIG_USERCONFIG:-$HOME/.npmrc}"
1040+
mkdir -p "$(dirname "$config_path")"
1041+
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > "$config_path"
1042+
npm whoami >/dev/null 2>&1 || { echo "npm auth failed (npm whoami). Confirm NPM_TOKEN has publish rights to @just-every/*" >&2; exit 1; }
10141043
shopt -s nullglob
10151044
for dir in npm-binaries/*; do
10161045
name=$(jq -r '.name' "$dir/package.json")
@@ -1033,10 +1062,10 @@ jobs:
10331062
shell: bash
10341063
run: |
10351064
set -euo pipefail
1036-
if ! npm whoami >/dev/null 2>&1; then
1037-
echo "npm auth unavailable; skipping main npm publish" >&2
1038-
exit 0
1039-
fi
1065+
config_path="${NPM_CONFIG_USERCONFIG:-$HOME/.npmrc}"
1066+
mkdir -p "$(dirname "$config_path")"
1067+
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > "$config_path"
1068+
npm whoami >/dev/null 2>&1 || { echo "npm auth failed (npm whoami). Confirm NPM_TOKEN has publish rights to @just-every/*" >&2; exit 1; }
10401069
name="@just-every/code"
10411070
version=$(jq -r '.version' package.json)
10421071
echo "Preparing to publish $name@$version"

0 commit comments

Comments
 (0)