Skip to content

ci: publish to npm from changesets with trusted publishing - #6

Merged
danielmlr merged 1 commit into
mainfrom
ci/release-workflow
Sep 25, 2026
Merged

danielmlr merged 1 commit into
mainfrom
ci/release-workflow

Conversation

@danielmlr

Copy link
Copy Markdown
Member

Publishes to npm from changesets, without an npm token.

How it works

.github/workflows/release.yml, built from changesets/action v2's sub-actions (their recommended layout for trusted publishing):

  • select-mode decides: changesets on main → version; none, and a version npm does not have → publish; otherwise nothing.
  • version opens or updates the "Version Packages" pull request (contents and pull-requests: write).
  • pack builds and packs the packages with read-only permissions.
  • publish is the only job with id-token: write. It installs with --ignore-scripts, builds nothing, and publishes the packed tarballs through npm trusted publishing, then tags and creates GitHub releases.

Actions are pinned by SHA like the compat workflow. pnpm handles the OIDC exchange from 11.1.3 on (the fix for an .npmrc written by setup-node); the repo pins 11.15.1, and the publish job prints the pnpm and npm versions.

Before it can publish

On https://www.npmjs.com/package/@eisbachcode/emdash-plugin-analytics → Settings → Trusted publishing, add a GitHub Actions publisher:

Field Value
Organization or user eisbachcode
Repository emdash-plugins
Workflow filename release.yml
Environment empty

The repository already allows GitHub Actions to create pull requests.

Merging this runs the workflow once: there are no changesets and 0.1.0 is already on npm, so it selects "none" and does nothing.

No changeset: CI only.

A release workflow built from changesets/action v2's sub-actions: with
changesets on main it opens a "Version Packages" pull request; once that
is merged, it packs the packages without credentials and publishes the
tarballs in a separate job, the only one allowed to mint an OIDC token
for npm trusted publishing. No npm token is stored anywhere.

Needs two settings before it can work: the trusted publisher on the
package's npmjs.com page (this repository, workflow release.yml), and
"Allow GitHub Actions to create and approve pull requests" in the
repository's Actions settings.
@danielmlr
danielmlr merged commit 7d75146 into main Sep 25, 2026
2 checks passed
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.

1 participant