ci(npm): preflight Trusted Publishing before building or publishing - #6
Merged
Conversation
Two consecutive release attempts failed with a bare: npm error 404 Not Found - PUT https://registry.npmjs.org/@planmonster%2folk-darwin-arm64 The 404 masks an authorization failure. From npm's lib/utils/oidc.js, Trusted Publishing is checked *per package* by exchanging a GitHub OIDC token at POST /-/npm/v1/oidc/token/exchange/package/<escaped-name>. A failed exchange is swallowed — logged at verbose level, then `return undefined` — after which npm falls back to whatever _authToken is configured. actions/setup-node writes the placeholder XXXXX-XXXXX-XXXXX-XXXXX there, so the registry rejects the PUT and the operator sees a 404 with no cause. Three problems, all addressed: 1. The failure was undiagnosable. NPM_CONFIG_LOGLEVEL=verbose on the publish step surfaces npm's own OIDC message. 2. The failure came late and could leave a partial release. The packages publish one at a time, so package 4 of 7 failing would strand a version that is immutable and can never be reused. A new `preflight` job exchanges a token for all seven names up front and reports exactly which are not ready, including the registry's message and the exact fields to fix. The build jobs now depend on it, so a misconfiguration costs ~20 s instead of ~6 min of Blacksmith and macOS time. 3. `always-auth: true` is not a valid input for actions/setup-node v6 and was emitting "Unexpected input(s)". Removed. The preflight job carries no job-level `if`: the build jobs depend on it, and a skipped dependency skips its dependents, which would have broken dry runs. The check is gated per step so a dry run leaves the job green.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughChangesNPM OIDC publishing
Sequence Diagram(s)sequenceDiagram
participant GitHubActions
participant GitHubOIDC
participant NPMRegistry
participant BuildJobs
participant PublishJob
GitHubActions->>GitHubOIDC: Request ID token for npm audience
GitHubActions->>NPMRegistry: Verify package token exchanges
NPMRegistry-->>GitHubActions: Return readiness responses
GitHubActions->>BuildJobs: Run builds after successful preflight
BuildJobs-->>GitHubActions: Produce build artifacts
GitHubActions->>PublishJob: Run publish after builds and preflight
PublishJob->>NPMRegistry: Publish with verbose npm logging
✨ Finishing Touches📝 Generate docstrings
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two release attempts (
30310389376,30311434844) both failed identically:What the 404 actually means
From npm's
lib/utils/oidc.js, Trusted Publishing is verified per package:On failure npm returns silently and falls back to the configured
_authToken.actions/setup-nodewrites the placeholderXXXXX-XXXXX-XXXXX-XXXXX(confirmed in the run env:NODE_AUTH_TOKEN: XXXXX-XXXXX-XXXXX-XXXXX), so the registry rejects the PUT and masks 403 as 404. npm 11.16.0 andid-token: writewere both fine — the exchange itself was refused for that package.Three defects this exposed
verboselevel and we ran at default. Now setsNPM_CONFIG_LOGLEVEL: verboseon the publish step.preflightjob exchanges a token for all seven names before anything is built, printing exactly which are not ready plus the registry's own message:Builds now depend on it, so a misconfiguration costs ~20 s instead of ~6 min of Blacksmith + macOS time.
3.
always-auth: trueis invalid foractions/setup-nodev6 (##[warning]Unexpected input(s) 'always-auth'). Removed.Job graph
preflightdeliberately carries no job-levelif— the build jobs depend on it, and a skipped dependency skips its dependents, which would have silently broken dry runs. The check is gated per step so a dry run leaves the job green.Note
Nothing was published in either failed attempt — all seven packages still show only
1.10.0-pm.1, so1.10.0-pm.2is still free and no version was burned.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is enabled.