Skip to content

Commit 5772778

Browse files
ci(npm): use trusted publishing OIDC instead of NPM_TOKEN
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 50b6299 commit 5772778

4 files changed

Lines changed: 38 additions & 10 deletions

File tree

.github/workflows/release.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ on:
1313

1414
permissions:
1515
contents: write
16+
id-token: write # npm trusted publishing (OIDC) — no NPM_TOKEN secret
1617

1718
env:
1819
RELEASE_TAG: ${{ github.event_name == 'workflow_dispatch' && format('v{0}', inputs.version) || github.ref_name }}
@@ -36,7 +37,6 @@ jobs:
3637
with:
3738
node-version: "24"
3839
cache: "pnpm"
39-
registry-url: https://registry.npmjs.org
4040

4141
- name: Install dependencies
4242
run: pnpm install --no-frozen-lockfile
@@ -89,16 +89,28 @@ jobs:
8989
env:
9090
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9191

92+
- name: Setup Node.js for npm publish
93+
uses: actions/setup-node@v4
94+
with:
95+
node-version: "24"
96+
registry-url: https://registry.npmjs.org
97+
9298
- name: Publish to npm
9399
continue-on-error: true
94-
env:
95-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
96100
run: |
97101
pnpm ui-modules:sync
98102
pnpm ui-modules:validate
99103
node -e "const fs=require('fs');const p=JSON.parse(fs.readFileSync('package.json','utf8'));delete p.private;fs.writeFileSync('package.json',JSON.stringify(p,null,2)+'\n')"
104+
npm --version
100105
npm publish --access public
101106
npm deprecate antora-dark-theme@* "Renamed — use valentus-theme (bundled dark mode). See https://github.com/antora-supplemental/valentus-theme" || true
107+
# Trusted publisher on npmjs.com (package → Settings → Trusted publishing):
108+
# Provider: GitHub Actions
109+
# Organization/user: antora-supplemental
110+
# Repository: antora-dark-mode
111+
# Workflow filename: release.yml
112+
# Environment: (leave blank unless this job sets `environment:`)
113+
# Requires npm CLI ≥ 11.5.1 (Node 24 on ubuntu-latest). No NPM_TOKEN.
102114

103115
- name: Resolve release commit
104116
id: rel

docs/maintainers/npm-republish-plan.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,25 @@ cd Z:\code\github.com\antora-supplemental\antora-dark-mode
4242
pnpm publish:npm
4343
```
4444

45-
**CI:** `.github/workflows/release.yml` publishes on semver tags when `NPM_TOKEN` is configured.
45+
**CI:** `.github/workflows/release.yml` publishes on semver tags using [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/) (OIDC). No `NPM_TOKEN` — configure the trusted publisher on npmjs.com instead (see below).
46+
47+
### npm trusted publisher (one-time, on npmjs.com)
48+
49+
Package **antora-dark-mode****Settings****Trusted publishing****GitHub Actions**:
50+
51+
| Field | Value |
52+
|-------|-------|
53+
| Organization or user | `antora-supplemental` |
54+
| Repository | `antora-dark-mode` |
55+
| Workflow filename | `release.yml` |
56+
| Environment | _(leave blank — workflow does not use a deployment environment)_ |
57+
| Allowed actions | `npm publish` |
58+
59+
Requires npm CLI ≥ 11.5.1 (Node 24 on GitHub-hosted runners). Provenance is generated automatically.
60+
61+
`workflow_dispatch` re-runs use the same `release.yml` filename — no separate npm entry needed.
62+
63+
After trusted publishing works, consider **Settings → Publishing access → Require 2FA and disallow tokens** for maximum security.
4664

4765
```powershell
4866
# After publish — deprecate legacy package name (if you own antora-dark-theme)
@@ -60,7 +78,7 @@ npm deprecate antora-dark-theme@* "Renamed — use antora-dark-mode. See https:/
6078

6179
## CI
6280

63-
`.github/workflows/release.yml`no change required for npm; optional future job for `npm publish` with `NPM_TOKEN` and `environment: npm` if maintainers want automated registry publish again.
81+
`.github/workflows/release.yml`npm publish via **trusted publishing** (OIDC, `id-token: write`). Configure the trusted publisher on npmjs.com for workflow `release.yml`; no `NPM_TOKEN` secret. See `docs/maintainers/npm-republish-plan.md`.
6482

6583
## Related docs
6684

docs/modules/guide/pages/index.adoc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ Dark mode toggle, FOUC prevention, and CSS overrides for the Antora Default UI.
66

77
For composed doc-site chrome (mast, header, layout), see link:https://github.com/antora-supplemental/valentus-theme[valentus-theme].
88

9-
== Demo
10-
11-
https://antora-supplemental.github.io/antora-dark-mode[Live demo on GitHub Pages]
12-
139
== Install
1410

1511
See xref:installation.adoc[Installation], xref:ui-modules.adoc[UI Modules], and xref:npm-distribution.adoc[npm distribution].

docs/modules/guide/pages/npm-distribution.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ Tarball ships overlay assets only:
7171

7272
. Bump `package.json` version (semver aligned with git tag, e.g. `1.3.0`).
7373
. Temporarily remove `"private": true` for publish only.
74-
. `npm publish --access public` from repo root.
74+
. `npm publish --access public` from repo root (local) **or** push a semver tag / run the Release workflow (CI uses link:https://docs.npmjs.com/trusted-publishers/[npm trusted publishing] — OIDC, no `NPM_TOKEN`).
7575
. Restore `"private": true` in git.
7676
. `npm deprecate antora-dark-mode@* ""` to clear the retirement banner on all versions.
7777

78+
CI trusted publisher (npmjs.com → package → Settings → Trusted publishing → GitHub Actions): org `antora-supplemental`, repo `antora-dark-mode`, workflow `release.yml`, environment blank.
79+
7880
=== 3. README and docs
7981

8082
* Replace `README.md` retirement notice with overlay-first install (link to Installation).

0 commit comments

Comments
 (0)