Skip to content

ci(release): pre-flight NPM_TOKEN check with actionable error annotation (refs #94)#97

Open
Abdeltoto wants to merge 1 commit into
smartsheet-platform:mainfrom
Abdeltoto:ci/release-npm-token-preflight
Open

ci(release): pre-flight NPM_TOKEN check with actionable error annotation (refs #94)#97
Abdeltoto wants to merge 1 commit into
smartsheet-platform:mainfrom
Abdeltoto:ci/release-npm-token-preflight

Conversation

@Abdeltoto

Copy link
Copy Markdown

👋 PR #3 of 3 from a Smartsheet power user (see #95 and #96 for context).

Problem

Issue #94 surfaced because the Release workflow's last several runs all failed with:

npm error code EINVALIDNPMTOKEN
npm error 401 Unauthorized - GET https://registry.npmjs.org/-/whoami

…which means the NPM_TOKEN repository secret is missing/expired/revoked. The actual fix lives in your repo settings, but the developer experience around it is rough today:

  • semantic-release only fails after Checkout → Setup Node → Install → Build → Test (~3-5 min wasted per run).
  • The error is buried in the @semantic-release/npm plugin output.
  • Maintainers have to scroll through hundreds of lines to learn "rotate the token".
  • A partial GitHub release is sometimes posted before the npm step fails.

Fix

This PR adds a tiny pre-flight step before semantic-release:

- name: Verify NPM_TOKEN
  env:
    NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  run: |
    # Fails fast with a GitHub Actions error annotation if the secret is
    # missing, expired, or revoked — instead of crashing inside semantic-release.

What it does:

  • If NPM_TOKEN is missing::error::Missing NPM_TOKEN annotation, immediate failure with instructions.
  • If NPM_TOKEN is invalid → runs npm whoami against registry.npmjs.org, fails with ::error::Invalid NPM_TOKEN annotation pointing at the token-creation docs.
  • If NPM_TOKEN is valid → prints the npm username and proceeds to the normal Release step (current behavior preserved).

The token is never written to the global npm config — it's piped through a scratch .npmrc.preflight that's deleted immediately after the check. No behavioral change for the happy path.

Why this isn't intrusive

  • No changes to .releaserc.json.
  • No changes to plugin order, branches, or release semantics.
  • A successful run produces 1 extra log line (NPM_TOKEN is valid for npm user: ...).
  • A failed run now displays a red annotation in the GitHub Actions UI saying exactly what to do.

Doesn't fix #94 by itself

The actual fix for #94 is to rotate the NPM_TOKEN secret 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

  • YAML syntax validated locally.
  • Logic traced for all three branches (missing token / invalid token / valid token).
  • npm test still 72/72 passed (no source changes).
  • Token never persists past the step — scratch .npmrc.preflight is rm -f'd in both the success and failure paths.

Refs #94. Standalone PR — does not depend on #95 or #96.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The automated release is failing 🚨

1 participant