Skip to content

release: publish to npm through trusted publishing; no npm token - #2

Closed
houman44 wants to merge 1 commit into
mainfrom
release-npm-trusted-publishing
Closed

houman44 wants to merge 1 commit into
mainfrom
release-npm-trusted-publishing

Conversation

@houman44

Copy link
Copy Markdown
Contributor

dunstan's Release workflow now publishes to npm through npm trusted publishing (OIDC) instead of a long-lived npm token. It's the same pattern @cejel/cejel uses in production (publish-npm.yml).

What changes in release.yml

  • No npm token. The publish step no longer sets NODE_AUTH_TOKEN from secrets.NPM_TOKEN. npm exchanges the job's OIDC token for a short-lived publish credential. The job already has id-token: write (for mcp-publisher login github-oidc) and environment: release.
  • npm 11.5.1 is installed before the publish, because trusted publishing needs 11.5.1 or later and Node 22 bundles npm 10.
  • setup-node's _authToken placeholder is removed before the publish, and its absence is asserted. Left in place, npm uses it instead of the OIDC exchange.
  • Unchanged: the publish step's name, its NPM_PUBLISHED re-run guard, --provenance --access public, the 15-minute serve wait, the MCP registry step and the GitHub release job.

src/__tests__/release-versions.test.ts gains one test pinning that shape: no NPM_TOKEN or NODE_AUTH_TOKEN, id-token: write, environment: release, and both new steps before the publish. Against the previous workflow it fails (expected … not to match /NPM_TOKEN|NODE_AUTH_TOKEN:/).

Before merging: set up the trusted publisher on npm

On npmjs.com, at dunstan → Settings → Trusted Publisher → GitHub Actions:

Field Value
Organization or user BargLabs
Repository dunstan
Workflow filename release.yml
Environment release

Order

  1. Add the trusted publisher above.
  2. Merge this PR.
  3. The next v* tag publishes through OIDC. Check that the version on npm shows "GitHub Actions" as its publisher, with a trusted publisher.
  4. Then delete the npm token and the repository's NPM_TOKEN secret.

If the token is deleted before step 3 succeeds, the next release cannot publish.

Checks run

  • scripts/preflight_fast.sh: Biome and typecheck pass.
  • vitest run src/__tests__/release-versions.test.ts: 140 of 140 pass.
  • Not run: a release. The workflow runs only on a v* tag or by dispatch, so the first real exercise is the next tag.

🤖 Generated with Claude Code

The Release workflow published dunstan with NODE_AUTH_TOKEN from the NPM_TOKEN secret. It now
publishes through npm trusted publishing, as @cejel/cejel's publish-npm.yml does: npm exchanges the
job's OIDC token (id-token: write, already granted for the MCP registry login) for a short-lived
credential, so no long-lived npm token is needed.

- Require npm 11.5.1 before the publish: trusted publishing needs 11.5.1 or later, and Node 22
  bundles npm 10.
- Remove setup-node's _authToken placeholder before the publish, and assert it is gone: left in
  place, npm uses it instead of the OIDC exchange.
- The publish step keeps its name, its NPM_PUBLISHED guard and --provenance --access public.
- release-versions.test.ts pins the shape: no NPM_TOKEN or NODE_AUTH_TOKEN, id-token: write,
  environment release, and the npm and placeholder steps before the publish. It fails against the
  previous workflow.

Needs, on npmjs.com, a trusted publisher on the dunstan package for BargLabs/dunstan, workflow
release.yml, environment release, before the next v* tag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@houman44

Copy link
Copy Markdown
Contributor Author

Superseded by the same change in the development repository, which was merged; it reaches this repository with the next release export. Closing this duplicate.

@houman44 houman44 closed this Nov 20, 2026
@houman44
houman44 deleted the release-npm-trusted-publishing branch November 20, 2026 04:21
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant