Skip to content

Commit 68d61c0

Browse files
committed
ci(react-components): switch publish job to npm Trusted Publishing (OIDC)
Drops the long-lived NPM_TOKEN secret in favour of GitHub-issued OIDC credentials exchanged via `npm publish --provenance`. Also adds `--ignore-scripts` so the publish step skips package.json's `prepublishOnly` (the verify job already ran tests + built the artifact this job downloads). Header comment updated with the npmjs.com setup steps so the next maintainer doesn't have to rediscover them.
1 parent 53ff5ca commit 68d61c0

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

.github/workflows/publish-react-components.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,23 @@ name: Publish @my-own-web-services/react-components
1414
# matches package.json, builds, runs tests, and runs `npm publish`
1515
# with provenance.
1616
#
17-
# Required repository secrets:
18-
# NPM_TOKEN — an "Automation" or "Granular" npm access token with
19-
# publish rights on the @my-own-web-services scope.
20-
# Required repository setup:
21-
# The @my-own-web-services org must exist on npmjs.org and the
22-
# publishing user/org token must have permission to publish scoped
23-
# packages with public access.
17+
# Authentication:
18+
# Uses npm Trusted Publishing (OIDC) — there is no long-lived
19+
# NPM_TOKEN. The `publish` job below requests an OIDC token from
20+
# GitHub (via `permissions.id-token: write`) and `npm publish
21+
# --provenance` exchanges it for a short-lived publish credential.
22+
#
23+
# Required npm setup (one-time, in npmjs.com UI):
24+
# On https://www.npmjs.com → Packages → @my-own-web-services/react-components
25+
# → Settings → Trusted Publishers → Add publisher → GitHub Actions:
26+
# Organization: my-own-web-services
27+
# Repository: mows
28+
# Workflow filename: publish-react-components.yml
29+
# Environment: (leave blank)
30+
# For the very first publish (the package doesn't exist yet),
31+
# configure the trusted publisher at the @my-own-web-services org
32+
# level instead, or do a one-off manual `npm publish` with a
33+
# personal token and then add the trusted publisher.
2434

2535
on:
2636
push:
@@ -139,13 +149,17 @@ jobs:
139149

140150
- name: Publish to npm
141151
working-directory: components/react
142-
env:
143-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
144152
run: |
145-
# `publishConfig` in package.json already sets access=public
146-
# and provenance=true; we still pass --provenance explicitly so
147-
# the run fails loudly if the OIDC token isn't available.
148-
npm publish --provenance --access public
153+
# Auth is handled via npm Trusted Publishing (OIDC) — no
154+
# NODE_AUTH_TOKEN env. `--provenance` forces npm to mint the
155+
# OIDC exchange, so the run fails loudly if the publisher
156+
# binding on npmjs.com isn't configured for this workflow.
157+
# `--ignore-scripts` skips package.json's `prepublishOnly`
158+
# (which calls pnpm). The verify job above already ran tests
159+
# and built the artifact this job downloaded — re-running
160+
# them here would also require installing pnpm in the
161+
# publish environment for no real safety gain.
162+
npm publish --provenance --access public --ignore-scripts
149163
150164
dry-run-publish:
151165
needs: verify

0 commit comments

Comments
 (0)