fix(ci): stop setup-node's .npmrc breaking every yarn step - #499
Merged
Merged
Conversation
The Publish workflow failed after 8 seconds, inside setup-node itself:
error Error: Failed to replace env in config: ${NODE_AUTH_TOKEN}
at envReplace (/usr/local/lib/node_modules/yarn/lib/cli.js:95448:16)
registry-url makes setup-node write an .npmrc containing the literal
${NODE_AUTH_TOKEN}, which npm expands at publish time. yarn 1 reads .npmrc too
and aborts on a variable that is not set, and cache: yarn on the same step
shells out to `yarn cache dir` immediately after writing that file — so the
step killed itself before the workflow reached anything of its own. Every yarn
step after it would have failed the same way, since NODE_AUTH_TOKEN was scoped
to the publish step.
Reproduced locally with that .npmrc and `yarn cache dir`: it fails with the
variable unset, and passes both when the variable is defined and when the file
does not yet exist.
Defining NODE_AUTH_TOKEN for the whole job would fix it in one line, but it
would also put the publish token in the environment of yarn install, test and
build — the steps that run third-party code. So the registry configuration
moves to a second setup-node placed after the last yarn step instead, which
keeps the token scoped to the publish itself. A check on the step ordering is
written into the comment that explains it, since adding a yarn step at the end
would silently reintroduce the failure.
Provenance is now also left to real releases. A dry run has nothing to attest,
and asking for an attestation of a publish that is not happening is a
needless way for the rehearsal to fail.
Nothing was published: the failure was well before npm ran, and npm still shows
0.15.0 as latest.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
My bug in #497. The
Publishworkflow failed after 8 seconds, and nothing was published — npm still shows0.15.0as latest, and nov1.0.0tag or release exists.What happened
It failed inside
setup-nodeitself, not in a step of mine.registry-urlmakessetup-nodewrite an.npmrccontaining the literal${NODE_AUTH_TOKEN}for npm to expand at publish time. yarn 1 also reads.npmrc, and aborts on a variable that is not set — andcache: yarnon the same step shells out toyarn cache dirimmediately after writing that file. The step killed itself before the workflow reached anything of its own.Every
yarnstep after it would have failed identically, sinceNODE_AUTH_TOKENwas scoped to the publish step.Reproduced locally with that exact
.npmrc:yarn cache dir, variable unsetyarn cache dir, variable definedyarn cache dir, no.npmrcyetThe fix, and why not the one-liner
Defining
NODE_AUTH_TOKENat job level fixes it in one line. I did not do that: it would put the publish token in the environment ofyarn install,yarn testandyarn build— the steps that run third-party code.Instead the registry configuration moves to a second
setup-nodeplaced after the last yarn step, so the token stays scoped to the publish itself:The invariant is nothing yarn-related runs after
.npmrcexists. I verified the ordering holds after the change, and wrote the reason into the comment beside it, since appending a yarn step at the end would silently reintroduce the failure.Also
Provenance is now left to real releases. A dry run has nothing to attest, so asking for an attestation of a publish that is not happening is just another way for the rehearsal to fail before it tells you anything useful.
After merging
Publishfrom the Actions tab — it is the--dry-runrehearsal, and should now get all the way through to packing the tarballgh release create v1.0.0 --title 1.0.0NPM_TOKENstill needs to be an npm automation token if your account requires 2FA to publish.🤖 Generated with Claude Code