Skip to content

feat(npm-publish)!: publish with OIDC only - #44

Open
rekmarks-consensys-1 wants to merge 4 commits into
mainfrom
ocap/npm-publish-oidc-only
Open

rekmarks-consensys-1 wants to merge 4 commits into
mainfrom
ocap/npm-publish-oidc-only

Conversation

@rekmarks-consensys-1

@rekmarks-consensys-1 rekmarks-consensys-1 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Lines added, by type

Code Tests Docs Generated Lockfiles Config Total
289 (34%) 407 (48%) 151 0 0 0 847

Makes npm-publish publish only with OIDC (npm trusted publishing), as upstream MetaMask/action-npm-publish v8 does (#149, #148, #162), and adds a script that publishes a placeholder version of a new package, so its trusted publisher can be configured before its first release.

To review: the first commit adds scripts/publish-placeholder.sh on its own; the second changes the action, its tests and the README.

Changes

  • npm-token is removed. Packages are published only with OIDC, staged, with provenance for public repositories. environment.sh no longer keeps YARN_NPM_AUTH_TOKEN, so a token set by the caller's job, which interferes with OIDC, is unset.
  • A package that has never been on npm fails the action before anything is published or packed, and every such package is listed. main.sh checks this, in parallel, with a new scripts/never-published.sh, after it finds the packages to publish and before the publish loop, so a release with a new package publishes nothing rather than part of the release. Unlike upstream, a dry run fails too, so the dry-run job reports it before the environment's approval.
  • dry-run is required and must be true or false. With it unset, a publish job whose id-token: write was missing used to pack and pass. With dry-run: false, a job without OIDC now fails in main.sh, before anything is published.
  • publish.sh has two modes: pack, or yarn npm publish --staged (plus --provenance for a public repository). The npm lookup and the token path are gone from it.
  • scripts/publish-placeholder.sh publishes <name>@0.0.0 for each given package directory, from a maintainer's workstation, logged in to npm:
    • It fails before publishing anything if a package is private, has an invalid name, is given twice, or has a version on npm other than 0.0.0 (looked up with npm-view.sh).
    • After confirmation, it publishes, with --access public, a package containing only package.json (name, version, and the workspace's description, license and repository) and a README saying it's a placeholder, then deprecates that version.
    • A package whose only version on npm is 0.0.0 is only deprecated, so running the script again finishes a run that stopped partway. A failing package doesn't stop the others; failures are listed at the end.
    • It builds and publishes in a new temporary directory with a package.json of its own, so nothing from the repository runs and no .npmrc applies other than the user's and the global one.
    • The action never publishes 0.0.0, so the placeholder can't collide with a release.
  • npm view runs in a private directory with its own package.json, instead of /tmp. npm loads the .npmrc beside the nearest package.json above its working directory as project configuration, so files planted in /tmp could otherwise answer the lookups. This was already the case before this PR; the PR relies on the lookups more.
  • README: new "New packages" and "Trusted publishers" sections, and updated Usage, Inputs, Behavior, Differences, Security and Tests sections. "Trusted publishers" records two constraints from npm's docs:
    • When the publish job is in a reusable workflow (workflow_call), npm checks the calling workflow's file name, and both workflows need id-token: write.
    • A new trusted-publisher configuration expires if it hasn't published within 2 days, so it should be created shortly before a release that publishes the package.
    • The action checks only that each package is on npm, not its trusted publisher. If that is missing or expired, the packages before it in the release are already staged when its publish fails; staged versions don't go live until approved.

Tests

  • test/publish-modes.sh:
    • Removed: the token cases.
    • Added:
      • never-published packages fail with dry-run true and false, without OIDC (so the check must come before the OIDC check), listing each, in a polyrepo and in a monorepo, with nothing packed or published;
      • the npm stand-in fails unless npm view runs in a directory with its own package.json;
      • dry-run: false without OIDC fails before any workspace is published;
      • an empty dry-run fails;
      • a YARN_NPM_AUTH_TOKEN from the job is unset before publishing.
    • Changed: "stops at the first failure" now uses a yarn stand-in that fails in one package, since a missing OIDC grant fails before the loop.
  • test/environment-variables.sh now expects YARN_NPM_AUTH_TOKEN to be unset.
  • New test/publish-placeholder.sh tests the placeholder script with an npm stand-in that keeps a fake registry: contents of the placeholder, the refusals, deprecating without re-publishing, and going on past a failure. It also fails unless npm runs in a directory with its own package.json. The modes job runs it.
  • .github/workflows/test_npm-publish.yml and test/make-fixture.sh:
    • Fixtures: the packages that fixtures pack had never been on npm, which now fails the action. They are now on npm, at a version that isn't (@types/node@999.0.0). None of these jobs has id-token: write, so nothing can be published.
    • New fixture and job: a new fixture adds a never-published package, and a new job expects it to fail with dry-run true and false, with nothing packed.
    • Updated jobs: rejected also covers an empty dry-run, and its registry fixture's package is on npm, so it would be packed without the registry check. polyrepo sets dry-run: true. The sanitize job's scope-registry override now targets @types.

The placeholder script's lookups were run locally against the real registry: a package already on npm and a duplicate are refused. It hasn't been used to publish anything. The new tests were checked by mutation: putting the OIDC check before the never-published check, running npm view from /tmp, and dropping the placeholder script's own package.json each make tests fail.

Breaking changes

  • npm-token is removed; callers must remove it.
  • dry-run is required.
  • A release that includes a package not yet on npm fails until a placeholder is published and the package's trusted publisher is configured.

🤖 Generated with Claude Code

rekmarks-consensys-1 and others added 2 commits December 2, 2026 14:14
OIDC can publish only a package that is already on npm, with its trusted
publisher configured. scripts/publish-placeholder.sh publishes an empty
0.0.0 of each given package from a workstation, after checking that it is
public and not on npm yet, and deprecates that version. The placeholder
is built in a temporary directory, so nothing from the repository runs
and its .npmrc files don't apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Remove the `npm-token` input. Packages are published only with OIDC
(npm trusted publishing), staged, with provenance for public
repositories, and a `YARN_NPM_AUTH_TOKEN` from the caller's job is unset.

If any package to publish has never been on npm, the action now fails
before publishing or packing anything, in a dry run too, and lists every
such package. Its first version is a placeholder published with
scripts/publish-placeholder.sh; the README's "New packages" section
describes the steps.

`dry-run` is now required and must be `true` or `false`: with it unset,
a publish job whose OIDC grant was missing used to pack and pass. With
`dry-run: false`, a job without OIDC fails before publishing anything.

The test fixtures' packages to publish are now on npm, at versions that
are not (`@types/node@999.0.0`), and a new fixture has a package that has
never been published.

BREAKING CHANGE: `npm-token` is removed, `dry-run` is required, and a
package that has never been published fails the action.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rekmarks-consensys-1
rekmarks-consensys-1 requested review from a team as code owners December 2, 2026 22:42
rekmarks-consensys-1 and others added 2 commits December 2, 2026 15:01
- Run `npm view` in a private directory with its own package.json, not
  in /tmp. npm loads the .npmrc next to the nearest package.json above
  its working directory as project configuration, so a package.json and
  an .npmrc with a proxy in /tmp could answer the lookups.
- publish-placeholder.sh: run npm in a directory with its own
  package.json for the same reason (an .npmrc in /tmp could read the npm
  token). Only deprecate a package whose only version on npm is 0.0.0,
  so running the script again finishes a run that stopped partway. Go on
  past a failing package and list the failures. Say so when there's no
  answer at the prompt. Reject `~` in new names, as npm does.
- README: the action checks only that each package is on npm, not its
  trusted publisher; describe what happens if that is missing or
  expired.
- Tests: the `registry` fixture's package is on npm, so the job fails if
  the registry check is removed; the never-published cases run without
  OIDC, so they fail if the OIDC check comes first; the npm shim fails
  unless npm view runs in a directory with its own package.json; and
  test/publish-placeholder.sh tests the placeholder script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pkdiff downloads <name>@latest with `npm pack` in a directory under the
system temporary directory, and npm loads the .npmrc next to the nearest
package.json above its working directory, so files in /tmp could
redirect the dry run's report download. report.sh now runs pkdiff in a
new private directory with an empty package.json, which is also its
TMPDIR, and the report step no longer sets `working-directory: /tmp`.

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

This branch has not been deployed

No deployments
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