fix(ci): build the example before the private-registry publish step - #5
Merged
Merged
Conversation
The example install failed with:
error Error: Failed to replace env in config: ${NODE_AUTH_TOKEN}
`setup-node` writes an .npmrc, and exports NPM_CONFIG_USERCONFIG pointing at
it, only when given `registry-url` — and it never unsets that for later steps.
That .npmrc always contains a literal `_authToken=${NODE_AUTH_TOKEN}`. Up
through v4 the action also exported a dummy token when none was supplied, so
the placeholder always resolved; v7 removed that fallback
(actions/setup-node#1558). npm tolerates the unresolved placeholder but yarn v1
hard-errors on it, so the reset-to-public-registry step could not work: any
`registry-url` step leaves an .npmrc that breaks a later bare `yarn`.
Order the example install and build before both publish steps instead, so they
run with no .npmrc at all on the default public registry. This also makes the
release fail fast: publishing is irreversible, so a broken example should stop
the release rather than leave a published package with no matching Pages
deploy.
Also use `--frozen-lockfile` for both installs so a release can't silently
resolve dependencies that differ from the committed lockfiles.
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.
Problem
The
install example dependenciesstep still fails in the publish workflow, now with a different error than the registry mismatch:The registry reset added previously was the right idea but can't work, and the
setup-node@v7bump is what exposed it.setup-nodewrites an.npmrc— and exportsNPM_CONFIG_USERCONFIGpointing at it — only when givenregistry-url, and it never unsets that for subsequent steps. The.npmrcit writes always contains a literal, unexpanded placeholder:Through v4, the action also exported a dummy
NODE_AUTH_TOKEN=XXXXX-XXXXX-XXXXX-XXXXXwhen the user supplied none, so that placeholder always resolved. actions/setup-node#1558 (in v7) removed the dummy fallback and now only exports the variable when explicitly set.The asymmetry that makes this bite: npm tolerates the unresolved placeholder, but yarn v1 hard-errors on it. Confirmed against yarn's
envReplace, which throws outright when the referenced variable is undefined.So the "reset the registry to public" approach was a dead end — any
registry-urlstep leaves behind an.npmrcthat breaks a later bareyarn, regardless of which registry it points at.Fix
Move the example install and build before both publish steps, so they run on the default public registry with no
.npmrcinvolved at all. No registry juggling needed.This has a second benefit worth calling out: publishing is irreversible (npm won't let you reuse a version), so validating the example first means a broken example stops the release instead of leaving a published package with no matching Pages deploy. The previous ordering published to two registries and then discovered the example was broken — which is what happened on the last three release attempts.
Also switched both installs to
--frozen-lockfile, so a release can't silently resolve dependencies that differ from the committed lockfiles.Resulting step order
Verification
.npmrccontaining the placeholder andNODE_AUTH_TOKENunset,yarn installfails with the identical error; with the variable set (the old v4 behavior) it succeeds — confirming the v7 change as the trigger..npmrc), example build →Compiled successfully., andexample/build/index.htmlexists for the Deploy step.--frozen-lockfilecheck, since thefile:../entry is recorded without a version.registry-url, and that nothing runningyarnfollows it.