Skip to content

Commit 855e9c9

Browse files
0xisktirumerla
andauthored
ci(release): adopt npm OIDC trusted publishing (#658)
Signed-off-by: 0xisk <0xisk@proton.me> Co-authored-by: Sai Tirumerla <57160285+tirumerla@users.noreply.github.com>
1 parent aeffce5 commit 855e9c9

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Publishes to npm via OIDC trusted publishing — no NPM_TOKEN.
2+
# Prerequisite: this repo + this workflow must be registered as a Trusted
3+
# Publisher for the package on npmjs.org (package → Settings → Trusted
4+
# Publishers), otherwise the publish step fails with an auth error.
15
name: Publish Package on Release
26

37
on:
@@ -13,6 +17,7 @@ jobs:
1317
permissions:
1418
contents: read
1519
id-token: write
20+
attestations: write # Write SLSA build provenance to the attestation store
1621

1722
steps:
1823
- name: Harden Runner
@@ -23,15 +28,22 @@ jobs:
2328
- name: Checkout
2429
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
2530
with:
26-
# No git writes here (publish goes through the npm token), so don't persist creds.
31+
# No git writes here (publish uses npm OIDC, not git creds), so don't persist creds.
2732
persist-credentials: false
2833

2934
- name: Setup Node.js
3035
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
3136
with:
3237
node-version-file: ".nvmrc"
38+
registry-url: https://registry.npmjs.org
3339
package-manager-cache: false # Prevent cache poisoning issues
3440

41+
- name: Ensure npm supports trusted publishing
42+
# OIDC trusted publishing requires npm >= 11.5.1. The .nvmrc Node may
43+
# bundle an older npm, so pin the floor explicitly: stays on the
44+
# vetted 11.x major, avoids a surprise npm major in a release run.
45+
run: npm install -g npm@^11.5.1
46+
3547
- name: Enable Corepack
3648
run: corepack enable
3749

@@ -56,11 +68,6 @@ jobs:
5668
fi
5769
echo "✅ Version consistency validated: $RELEASE_VERSION"
5870
59-
- name: Setup npm registry
60-
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
61-
with:
62-
registry-url: "https://registry.npmjs.org"
63-
6471
- name: Pack tarball
6572
id: pack
6673
run: |
@@ -100,14 +107,21 @@ jobs:
100107
exit 1
101108
fi
102109
110+
- name: Attest build provenance
111+
# Signed SLSA v1 provenance over the exact tarball, stored in the
112+
# GitHub attestation store (verifiable with `gh attestation verify`).
113+
# Complements the npm-registry provenance from NPM_CONFIG_PROVENANCE.
114+
uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1
115+
with:
116+
subject-path: ${{ steps.pack.outputs.tarball }}
117+
103118
- name: Publish to npm
104119
run: |
105120
# Publish the tarball with appropriate tag
106121
npm publish "${{ steps.pack.outputs.tarball }}" --tag "${{ steps.pack.outputs.tag }}" --access public
107122
env:
123+
# No NODE_AUTH_TOKEN — OIDC trusted publishing mints per-run credentials.
108124
NPM_CONFIG_PROVENANCE: true
109-
# Token required for actions/setup-node
110-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
111125

112126
- name: Log success
113127
run: |

0 commit comments

Comments
 (0)