Skip to content

Commit efd7ad2

Browse files
billfienbergclaude
andauthored
Support OIDC authentication for NPM publishing (#52)
* Support OIDC authentication for NPM publishing NPM has deprecated classic tokens, so this adds support for OIDC authentication (Trusted Publishers) as an alternative to NPM_TOKEN. - Make NPM_TOKEN optional - only configure .npmrc when provided - For OIDC, npm handles auth automatically via GitHub's OIDC provider - Add documentation for OIDC setup in README - Bump version to 0.0.16 Fixes #50 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Remove NPM_TOKEN support, require OIDC authentication - Change OIDC from "recommended" to "required" - Add npm CLI 11.5.2+ version requirement for OIDC - Remove NPM_TOKEN workflow example and documentation - Remove NPM_TOKEN handling code from index.ts Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Bump version to 0.1.0 for breaking changes Minor version bump per SemVer conventions for pre-1.0.0 breaking changes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Keep NPM_TOKEN support for backwards compatibility Mark NPM_TOKEN as deprecated but still functional for external users who may have valid tokens. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Remove NPM_TOKEN support completely OIDC authentication is now the only supported method for npm publishing. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e319ccb commit efd7ad2

4 files changed

Lines changed: 32 additions & 21 deletions

File tree

README.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ This GitHub action allows for automation of [Changesets Snapshot Release](https:
1212

1313
Create a `.github/workflows/snapit.yml` file with the following contents.
1414

15-
**Deploy to NPM**
15+
**Deploy to NPM (with OIDC authentication)**
16+
17+
OIDC authentication using [NPM Trusted Publishers](https://docs.npmjs.com/trusted-publishers) is required as [NPM has deprecated classic tokens](https://github.blog/changelog/2025-09-29-strengthening-npm-security-important-changes-to-authentication-and-token-management/).
18+
19+
> **Note:** OIDC requires npm CLI version 11.5.2 or later. Earlier versions will fail with cryptic errors.
1620
1721
```yml
1822
name: Snapit
@@ -26,15 +30,26 @@ jobs:
2630
snapit:
2731
name: Snapit
2832
runs-on: ubuntu-latest
33+
permissions:
34+
contents: read
35+
id-token: write
36+
issues: write
37+
pull-requests: write
2938
steps:
3039
- name: Checkout default branch
3140
uses: actions/checkout@v4
3241

42+
- name: Setup Node.js
43+
uses: actions/setup-node@v4
44+
with:
45+
node-version: '20'
46+
registry-url: 'https://registry.npmjs.org'
47+
3348
- name: Create snapshot version
3449
uses: Shopify/snapit@main
3550
env:
3651
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
52+
NPM_CONFIG_PROVENANCE: true
3853
with:
3954
build_script: pnpm build # Optional
4055
trigger_comment: /snapit # Default value not required
@@ -75,9 +90,15 @@ jobs:
7590

7691
The `GITHUB_TOKEN` is needed for changesets to look up the current changeset when creating a snapshot. You can use the automatically created [`${{ secrets.GITHUB_TOKEN }}` to authenticate in the workflow job](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret).
7792

78-
**`NPM_TOKEN`**
93+
**OIDC Authentication**
7994

80-
A `NPM_TOKEN` needs to be created and added to the repository to [publish packages from GitHub actions to the npm registry](https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages#publishing-packages-to-the-npm-registry).
95+
Use [NPM Trusted Publishers](https://docs.npmjs.com/trusted-publishers) with OIDC authentication. This is required as NPM has deprecated classic tokens. To use OIDC:
96+
97+
1. Configure your npm package to trust your GitHub repository (see [NPM Trusted Publishers documentation](https://docs.npmjs.com/trusted-publishers))
98+
2. Ensure npm CLI version 11.5.2 or later is installed
99+
3. Add `id-token: write` permission to your workflow
100+
4. Use `actions/setup-node` with `registry-url: 'https://registry.npmjs.org'`
101+
5. Set `NPM_CONFIG_PROVENANCE: true` environment variable
81102

82103
## GitHub Action Inputs
83104

@@ -107,6 +128,11 @@ To contribute a change, bug fix or feature to snapit:
107128

108129
## Changelog
109130

131+
**`v0.1.0`**
132+
133+
- **Breaking:** Require OIDC authentication (NPM Trusted Publishers). `NPM_TOKEN` is no longer supported.
134+
- OIDC requires npm CLI version 11.5.2 or later
135+
110136
**`v0.0.15`**
111137

112138
- Add `release_branch` to configure the default release branch. Default is `changeset-release/main`.

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,6 @@ try {
188188
await exec('git', ['checkout', '-b', branch]);
189189
await exec('git', ['push', '--force', 'origin', branch]);
190190
} else {
191-
if (!process.env.NPM_TOKEN) {
192-
throw new Error(
193-
'Please provide the NPM_TOKEN to the snapit GitHub action',
194-
);
195-
}
196-
197-
await exec(
198-
'bash',
199-
[
200-
'-c',
201-
`echo "//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}" > "$HOME/.npmrc"`,
202-
],
203-
silentOption,
204-
);
205-
206191
await exec(changesetBinary, [
207192
'publish',
208193
'--no-git-tags',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "snapit",
33
"private": true,
4-
"version": "0.0.15",
4+
"version": "0.1.0",
55
"description": "Create a snapshot NPM release with `/snapit` comment in a PR",
66
"type": "module",
77
"scripts": {

0 commit comments

Comments
 (0)