Skip to content

ci(prerelease): gate npm publish behind a protected environment - #295

Merged
Bccorb merged 1 commit into
mainfrom
ci/gate-prerelease-environment
Nov 23, 2026
Merged

Bccorb merged 1 commit into
mainfrom
ci/gate-prerelease-environment

Conversation

@Bccorb

@Bccorb Bccorb commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #286 (M22). Part of fells-code/seamless-auth-api#603, step 6.

What changed

.github/workflows/prerelease.yml now has two jobs.

  • test runs with contents: read only. It works out the channel, checks for pending changesets, installs and runs pnpm test. Code on a pushed dev or release/** branch no longer runs in a job that can mint an npm OIDC token.
  • publish needs test, runs only when changesets are pending, and runs in the npm-prerelease environment. It is the only job with id-token: write. With required reviewers on the environment, every prerelease publish waits for an approval.

Injection hardening:

  • github.event_name, inputs.tag, github.ref_name and the channel output reach the shell through env: and are quoted. No ${{ }} expression is left inside a run: block.
  • The channel tag must be alpha, beta or rc, otherwise the job fails before any publish.
  • Both checkouts set persist-credentials: false.

The other workflows were checked for the same pattern. ci.yml, conformance.yml, manifest.yml and release.yml have no ${{ }} inside run: blocks (only in env:, with:, concurrency and job names), so they are unchanged. release.yml also publishes with id-token: write and no environment. That is outside M22 and is left for a follow-up.

No changeset: this is a CI-only change with no package impact.

Required before merge

Checked read-only on 2026-11-20: the repo has no environments, its only ruleset (dev) is disabled and targets no refs, release/** has no effective rules, and dev has no branch protection. The npm trusted-publisher binding is not visible from GitHub.

Without the environment below, GitHub creates npm-prerelease automatically on the first run with no protection, so the gate does nothing until it is configured. These settings must exist before this merges:

  1. Environment npm-prerelease (Settings, Environments):
    • Required reviewers: at least one maintainer. Turn on "Prevent self-review".
    • Deployment branches and tags: "Selected branches and tags", limited to dev and release/**.
    • No environment secrets. Publishing uses OIDC trusted publishing.
  2. Branch ruleset for release/** (Settings, Rules, Rulesets), enforcement Active:
    • Target: include refs/heads/release/**.
    • Rules: "Restrict creations", "Restrict deletions" and "Block force pushes".
    • Bypass list: maintainers only.
  3. npm trusted publisher for @seamless-auth/core, @seamless-auth/express, @seamless-auth/fastify and @seamless-auth/nextjs (npmjs.com, package Settings, Trusted publishing). The binding could not be read from GitHub, so check it before merge:
    • If it already names an environment, that environment must be npm-prerelease or prerelease publishing fails.
    • If it names no environment, prerelease publishing keeps working. Restricting it to npm-prerelease would also block release.yml, which runs in no environment, so keep the environment field empty until stable releases get their own environment.
    • npm matches the workflow file name (prerelease.yml), not the job name, so renaming the job from prerelease to publish does not affect the binding.

Checks

  • actionlint: clean.
  • pnpm install --frozen-lockfile && pnpm test: all packages pass.
  • The repo has no lint or format script and no prettier config. The workflow keeps the existing quoting style of the other workflow files.

Split the workflow into a test job without id-token: write and a publish
job that runs in the protected npm-prerelease environment. Pass the event
name, dispatch input, ref name and channel tag through env: instead of
interpolating them into run: blocks, and reject any tag outside
alpha, beta and rc.

Refs #286
@Bccorb
Bccorb merged commit 18313cd into main Nov 23, 2026
6 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.

ci(prerelease): gate npm prerelease publishing behind a protected environment

1 participant