Skip to content

Commit e3b3578

Browse files
committed
fix: fail fast without npm trusted publishing
1 parent 53e1a68 commit e3b3578

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

.github/workflows/release.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,25 @@ jobs:
3535
- name: Audit packed tarball surface
3636
run: npm pack --dry-run --json
3737

38+
- name: Verify npm trusted publisher
39+
run: |
40+
OIDC_TOKEN=$(curl -fsSL \
41+
-H "Authorization: Bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" \
42+
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=npm:registry.npmjs.org" \
43+
| jq -r '.value')
44+
STATUS=$(curl -sS \
45+
-o /tmp/npm-oidc.json \
46+
-w "%{http_code}" \
47+
-X POST "https://registry.npmjs.org/-/npm/v1/oidc/token/exchange/package/gsdd-cli" \
48+
-H "Authorization: Bearer ${OIDC_TOKEN}")
49+
if [ "${STATUS}" != "200" ]; then
50+
cat /tmp/npm-oidc.json
51+
echo "::error::npm trusted publishing is not configured for gsdd-cli. Configure npm package trusted publisher for PatrickSys/workspine using .github/workflows/release.yml before running semantic-release."
52+
exit 1
53+
fi
54+
3855
- name: Release
3956
env:
4057
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4258
NPM_CONFIG_PROVENANCE: "true"
4359
run: npx semantic-release

tests/gsdd.guards.test.cjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3044,12 +3044,12 @@ describe('G43 - Release Packaging Audit', () => {
30443044
'release.yml must use Node 22.14.0+ for npm trusted publishing. FIX: Keep setup-node on 22.14.0 or newer.');
30453045
assert.match(releaseWorkflow, /npm install -g npm@11/i,
30463046
'release.yml must install npm 11 for trusted publishing. FIX: Keep the npm@11 setup step.');
3047-
assert.match(releaseWorkflow, /NPM_TOKEN: \$\{\{ secrets\.NPM_TOKEN \}\}/i,
3048-
'release.yml must expose NPM_TOKEN as a fallback when npm trusted publishing is not configured. FIX: Pass secrets.NPM_TOKEN to semantic-release.');
3047+
assert.match(releaseWorkflow, /Verify npm trusted publisher[\s\S]*oidc\/token\/exchange\/package\/gsdd-cli[\s\S]*before running semantic-release/i,
3048+
'release.yml must fail fast before semantic-release when npm trusted publishing is not configured. FIX: Keep the trusted-publisher preflight before Release.');
30493049
assert.doesNotMatch(releaseWorkflow, /registry-url: https:\/\/registry\.npmjs\.org/i,
30503050
'release.yml must not let setup-node create placeholder npm auth that masks NPM_TOKEN fallback. FIX: Remove setup-node registry-url.');
3051-
assert.doesNotMatch(releaseWorkflow, /loginoauth|ACTIONS_ID_TOKEN_REQUEST_TOKEN|NPM_TOKEN=\$\{NPM_TOKEN\}/i,
3052-
'release.yml must not hand-roll npm OIDC token exchange. FIX: Let @semantic-release/npm own trusted publishing.');
3051+
assert.doesNotMatch(releaseWorkflow, /loginoauth|NPM_TOKEN/i,
3052+
'release.yml must not hand-roll npm token exchange or fall back to OTP-prone tokens. FIX: Use trusted publishing only.');
30533053
assert.match(releaseWorkflow, /NPM_CONFIG_PROVENANCE: "true"/i,
30543054
'release.yml must keep npm provenance enabled for semantic-release. FIX: Preserve NPM_CONFIG_PROVENANCE in the release env.');
30553055
assert.match(releaseWorkflow, /run: npx semantic-release/i,

0 commit comments

Comments
 (0)