ci(release): pre-flight NPM_TOKEN check with actionable error annotation (refs #94)#97
Open
Abdeltoto wants to merge 1 commit into
Open
Conversation
…martsheet-platform#94) When the NPM_TOKEN secret is missing, expired, or revoked, semantic-release fails deep in the @semantic-release/npm plugin with a generic 'EINVALIDNPMTOKEN' / 401 stack trace, after the workflow has already run install + build + test (~3-5 min wasted) and posted a partial GitHub release. This change adds a tiny preflight step that runs npm whoami against registry.npmjs.org with the configured token, before invoking semantic-release. If the token is missing or invalid, the workflow fails immediately with a GitHub Actions error annotation explaining exactly what to fix and where, instead of forcing maintainers to dig through the semantic-release log. The token never touches the global npm config — it is written to a scratch .npmrc that is read only for whoami, then deleted. Refs smartsheet-platform#94. Made-with: Cursor
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.
👋 PR #3 of 3 from a Smartsheet power user (see #95 and #96 for context).
Problem
Issue #94 surfaced because the
Releaseworkflow's last several runs all failed with:…which means the
NPM_TOKENrepository secret is missing/expired/revoked. The actual fix lives in your repo settings, but the developer experience around it is rough today:semantic-releaseonly fails afterCheckout → Setup Node → Install → Build → Test(~3-5 min wasted per run).@semantic-release/npmplugin output.Fix
This PR adds a tiny pre-flight step before
semantic-release:What it does:
NPM_TOKENis missing →::error::Missing NPM_TOKENannotation, immediate failure with instructions.NPM_TOKENis invalid → runsnpm whoamiagainstregistry.npmjs.org, fails with::error::Invalid NPM_TOKENannotation pointing at the token-creation docs.NPM_TOKENis valid → prints the npm username and proceeds to the normalReleasestep (current behavior preserved).The token is never written to the global npm config — it's piped through a scratch
.npmrc.preflightthat's deleted immediately after the check. No behavioral change for the happy path.Why this isn't intrusive
.releaserc.json.NPM_TOKEN is valid for npm user: ...).Doesn't fix #94 by itself
The actual fix for #94 is to rotate the
NPM_TOKENsecret in repo settings — that's an internal Smartsheet operation. This PR makes the failure mode for #94 (and any future expiry) loud, fast, and self-documenting so the next time it happens, the on-call sees the fix in 5 seconds instead of 5 minutes.Test plan
npm teststill 72/72 passed (no source changes)..npmrc.preflightisrm -f'd in both the success and failure paths.Refs #94. Standalone PR — does not depend on #95 or #96.