fix(ci): declare the production environment so the token reaches the job - #500
Merged
Merged
Conversation
NPM_TOKEN was added as a secret of the production environment rather than as a repository secret. An environment's secrets are only visible to a job that declares that environment, and the publish job declared none, so secrets.NPM_TOKEN resolved to empty. The rehearsal could not catch this. npm only warns about missing authentication under --dry-run, so the manual run went green while a real release would have failed at npm publish with a 403 — which reads like a problem with the npm account rather than a secret that never arrived. Declaring the environment is the better fix than moving the secret. Environment secrets bring protection rules with them: required reviewers, wait timers, and a restriction on which branches and tags may deploy. Limiting the latter to v* makes it impossible to publish from anything but a release tag, which is stronger than the tag check this workflow does for itself. Also adds a guard for the case in general, next to the tag check and before the gate rather than after it. An empty token fails a release immediately with a message naming the cause, and warns without failing on a rehearsal, where there is nothing to authenticate against anyway. 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.
NPM_TOKENwas added as a secret of theproductionenvironment, not as a repository secret:An environment's secrets are only visible to a job that declares that environment. The publish job declared none, so
secrets.NPM_TOKENresolved to empty and a real release would have failed atnpm publishwith a 403 — which reads like a problem with the npm account rather than a secret that never arrived.The rehearsal could not have caught this. npm only warns about missing authentication under
--dry-run, so the manual run went green.Declaring the environment, rather than moving the secret
Your setup is the better one, so the workflow now adapts to it:
Environment secrets bring protection rules with them — required reviewers, wait timers, and a restriction on which branches and tags may deploy. Worth using now that the job declares it:
That makes it impossible to publish from anything but a release tag, which is a stronger guarantee than the tag check this workflow performs on itself. Currently set to "No restriction", and there are no protection rules, so merging this changes nothing about what is allowed — it only makes those controls available.
Plus a guard for the general case
A missing token now fails before the gate rather than after it, with a message naming the cause:
::error::NPM_TOKEN is empty…This is the same class of mistake as the tag mismatch, which I guarded and this one I did not. It sits next to that check, so both cheap failures happen in the first ~30 seconds instead of after lint, tests and three build checks.
After merging
Re-run
Publishfrom the Actions tab. With the environment declared, the guard should now print "NPM_TOKEN is reaching this job" instead of the warning — which is the confirmation the earlier rehearsal could not give you. Thengh release create v1.0.0 --title 1.0.0 --generate-notes.🤖 Generated with Claude Code