Skip to content

Commit 638f15b

Browse files
committed
fix(publish): gate --provenance on GITHUB_ACTIONS to unbreak local runs
`npm publish --provenance` requires the GitHub Actions OIDC id-token endpoint — running the script locally (or in any non-GHA environment) fails with: "Provenance generation in GitHub Actions requires 'id-token: write' permission" Guarded the flag behind `process.env.GITHUB_ACTIONS === 'true'` so local emergency publishes (classic npm-token auth, no OIDC) still work. CI runs unchanged — GITHUB_ACTIONS is always `true` there, so provenance attestations are attached to every CI-published tarball exactly as before. Same fix was applied to stuie's scripts/publish.mts earlier today and is going out to socket-packageurl-js / socket-sdk-js in parallel commits.
1 parent 1ae9941 commit 638f15b

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

scripts/npm/publish-npm-packages.mts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,22 @@ async function publishTrusted(pkg, state, options) {
411411
await new Promise(resolve => setTimeout(resolve, delay))
412412
}
413413

414-
// Use npm for trusted publishing with OIDC tokens.
415-
416-
const result = await spawn(
417-
'npm',
418-
['publish', '--provenance', '--access', 'public'],
419-
{
420-
cwd: pkg.path,
421-
env: {
422-
...process.env,
423-
// Don't set NODE_AUTH_TOKEN for trusted publishing - uses OIDC.
424-
},
425-
shell: WIN32,
414+
// Use npm for trusted publishing with OIDC tokens. `--provenance`
415+
// requires the GitHub Actions OIDC id-token endpoint, so it's
416+
// gated on GITHUB_ACTIONS=true — local emergency publishes (run
417+
// with a classic npm token) still work without provenance.
418+
const publishArgs = ['publish', '--access', 'public']
419+
if (process.env['GITHUB_ACTIONS'] === 'true') {
420+
publishArgs.splice(1, 0, '--provenance')
421+
}
422+
const result = await spawn('npm', publishArgs, {
423+
cwd: pkg.path,
424+
env: {
425+
...process.env,
426+
// Don't set NODE_AUTH_TOKEN for trusted publishing - uses OIDC.
426427
},
427-
)
428+
shell: WIN32,
429+
})
428430
if (result.stdout) {
429431
logger.log(result.stdout)
430432
}

0 commit comments

Comments
 (0)