Skip to content

Commit ebf543b

Browse files
authored
Merge pull request #124 from PMDevSolutions/chore/npm-trusted-publishing
ci: publish to npm via OIDC trusted publishing
2 parents ee94763 + 2cebdac commit ebf543b

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

.github/workflows/publish-npm.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ name: Publish to npm
88
# current version already exists, so re-running release-please is a no-op), and
99
# - recovering from a failed release publish without waiting for the next release.
1010
#
11-
# Requires the NPM_TOKEN secret to be an npm token that can publish the package
12-
# (and create it on first publish) and bypasses 2FA — a granular token with
13-
# "All packages" + read/write, or an account-scoped token. Publishes with
14-
# provenance (needs id-token).
11+
# Auth uses npm Trusted Publishing (OIDC) — there is no NPM_TOKEN secret. A
12+
# trusted publisher matching this repo + workflow filename must be configured
13+
# on each package at npmjs.com. Requires id-token: write and npm >= 11.5.1, so
14+
# we upgrade the runner's bundled npm before publishing. Provenance is
15+
# generated automatically.
1516
on:
1617
workflow_dispatch:
1718
inputs:
@@ -49,20 +50,26 @@ jobs:
4950
with:
5051
version: 9
5152

53+
# registry-url is required for OIDC trusted publishing: it points npm at
54+
# the registry to mint the short-lived token against. setup-node also
55+
# writes a placeholder _authToken, which npm ignores in favour of OIDC as
56+
# long as a matching trusted publisher is configured for this package.
5257
- uses: actions/setup-node@v4
5358
with:
5459
node-version: 20
5560
registry-url: https://registry.npmjs.org
5661
cache: pnpm
5762
cache-dependency-path: ${{ inputs.package }}/pnpm-lock.yaml
5863

64+
# Trusted Publishing (OIDC) needs npm >= 11.5.1; Node 20 ships npm 10.x.
65+
- name: Upgrade npm for trusted publishing
66+
run: npm install -g npm@latest
67+
5968
- name: Install
6069
run: pnpm install --frozen-lockfile
6170

6271
- name: Build
6372
run: pnpm build
6473

6574
- name: Publish
66-
env:
67-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6875
run: npm publish --provenance --access public --tag "${{ inputs.dist-tag }}"

0 commit comments

Comments
 (0)