Skip to content

Commit 2531899

Browse files
authored
Merge pull request #127 from PMDevSolutions/ci/npm-trusted-publishing
ci: publish to npm via Trusted Publishing (OIDC), drop NPM_TOKEN
2 parents 7db2819 + 95e350d commit 2531899

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

.github/workflows/publish-npm.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
name: Publish to npm
22

3-
# Manual, on-demand publish of a package to npm.
3+
# Manual, on-demand publish of a package to npm, to recover from a failed
4+
# release publish without waiting for the next release. (release-please.yml
5+
# publishes automatically when it cuts a release.)
46
#
5-
# The release-please workflow already publishes automatically when it cuts a
6-
# release. This workflow exists for the cases that one can't handle:
7-
# - bootstrapping the very first publish of a package (the release for the
8-
# current version already exists, so re-running release-please is a no-op), and
9-
# - recovering from a failed release publish without waiting for the next release.
7+
# Auth uses npm Trusted Publishing (OIDC) — there is no NPM_TOKEN secret.
8+
# Requires id-token: write and npm >= 11.5.1, so we upgrade the runner's
9+
# bundled npm before publishing. Provenance is generated automatically.
1010
#
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.
11+
# NOTE: npm allows only ONE trusted publisher per package, configured here for
12+
# release-please.yml. To publish from THIS workflow instead, temporarily
13+
# repoint the package's trusted publisher (npmjs.com -> package Settings) to
14+
# publish-npm.yml, dispatch, then switch it back. A brand-new package's FIRST
15+
# publish cannot use OIDC at all — publish it once with a token (locally), then
16+
# configure trusted publishing.
1617
on:
1718
workflow_dispatch:
1819
inputs:
@@ -56,7 +57,7 @@ jobs:
5657
# long as a matching trusted publisher is configured for this package.
5758
- uses: actions/setup-node@v4
5859
with:
59-
node-version: 20
60+
node-version: 22
6061
registry-url: https://registry.npmjs.org
6162
cache: pnpm
6263
cache-dependency-path: ${{ inputs.package }}/pnpm-lock.yaml

.github/workflows/release-please.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,14 @@ jobs:
7676
gh release upload "${{ steps.release.outputs.tag_name }}" \
7777
cdn/claudius.iife.js cdn/claudius.css --clobber
7878
79-
# On merge, publish the widget to npm. Runs against the default checkout
80-
# (main at the released commit), which carries the version release-please
81-
# just bumped. --provenance signs the package via the id-token permission.
79+
# On merge, publish to npm via Trusted Publishing (OIDC) — no long-lived
80+
# NPM_TOKEN. Each package has a trusted publisher configured at npmjs.com
81+
# matching this repo + this workflow filename (release-please.yml); the
82+
# id-token: write permission above lets npm mint a short-lived token.
83+
# Trusted Publishing needs npm >= 11.5.1 (newer than Node's bundled npm),
84+
# so we upgrade npm first. Provenance is generated automatically. Runs
85+
# against the default checkout (main at the released commit), which carries
86+
# the version release-please just bumped.
8287
- name: Setup pnpm (npm publish)
8388
if: ${{ steps.release.outputs.release_created }}
8489
uses: pnpm/action-setup@v4
@@ -89,16 +94,18 @@ jobs:
8994
if: ${{ steps.release.outputs.release_created }}
9095
uses: actions/setup-node@v4
9196
with:
92-
node-version: 20
97+
node-version: 22
9398
registry-url: https://registry.npmjs.org
9499
cache: pnpm
95100
cache-dependency-path: widget/pnpm-lock.yaml
96101

102+
- name: Upgrade npm for trusted publishing
103+
if: ${{ steps.release.outputs.release_created }}
104+
run: npm install -g npm@latest
105+
97106
- name: Build and publish widget
98107
if: ${{ steps.release.outputs.release_created }}
99108
working-directory: widget
100-
env:
101-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
102109
run: |
103110
pnpm install --frozen-lockfile
104111
pnpm build
@@ -107,8 +114,6 @@ jobs:
107114
- name: Build and publish create-claudius
108115
if: ${{ steps.release.outputs.release_created }}
109116
working-directory: create-claudius
110-
env:
111-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
112117
run: |
113118
pnpm install --frozen-lockfile
114119
pnpm build

0 commit comments

Comments
 (0)