Skip to content

Commit 764af68

Browse files
authored
docs(readme): switch main example to trusted publishing (#257)
1 parent 680fd95 commit 764af68

File tree

1 file changed

+23
-41
lines changed

1 file changed

+23
-41
lines changed

README.md

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ jobs:
3232
contents: read
3333
id-token: write
3434
steps:
35-
- uses: actions/checkout@v5
36-
- uses: actions/setup-node@v5
35+
- uses: actions/checkout@v6
36+
- uses: actions/setup-node@v6
3737
with:
3838
node-version: "24"
3939
registry-url: "https://registry.npmjs.org"
4040
- run: npm ci
4141
- run: npm test
42-
- run: npm publish --provenance --ignore-scripts
43-
env:
44-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
42+
- run: npm publish --ignore-scripts
4543
```
4644
4745
See GitHub's [Node.js publishing][] guide and npm's [trusted publishing][] docs for more details and examples.
@@ -78,7 +76,7 @@ This package can be used three different ways:
7876

7977
## GitHub Action
8078

81-
To use the GitHub Action, you'll need to add it as a step in your [workflow file][]. By default, the only thing you need to do is set the `token` parameter to your [npm authentication token][].
79+
To use the GitHub Action, you'll need to add it as a step in your [workflow file][]. By default, the only thing you need to do is set `permissions.id-token` to `write` to enable [trusted publishing][] via OIDC.
8280

8381
```yaml
8482
on:
@@ -88,41 +86,27 @@ on:
8886
jobs:
8987
publish:
9088
runs-on: ubuntu-latest
89+
permissions:
90+
contents: read
91+
id-token: write
9192
steps:
92-
- uses: actions/checkout@v5
93-
- uses: actions/setup-node@v5
93+
- uses: actions/checkout@v6
94+
- uses: actions/setup-node@v6
9495
with:
9596
node-version: "24"
9697
- run: npm ci
9798
- run: npm test
9899
- uses: JS-DevTools/npm-publish@v4
99-
with:
100-
token: ${{ secrets.NPM_TOKEN }}
101100
```
102101

103-
If you have [trusted publishing][] configured for your package and use `npm@>=11.5.1`, you can omit the `token` input and use OIDC instead.
104-
105102
> [!IMPORTANT]
106-
> If you're publishing a private package, you will still need to provide a read-only `token` so the action can read existing versions from the registry before publish.
107-
108-
```diff
109-
jobs:
110-
publish:
111-
runs-on: ubuntu-latest
112-
+ permissions:
113-
+ contents: read
114-
+ id-token: write # required to use OIDC
115-
steps:
116-
- uses: actions/checkout@v5
117-
- uses: actions/setup-node@v5
118-
with:
119-
node-version: "24" # includes npm@11.6.0
120-
- run: npm ci
121-
- run: npm test
122-
- uses: JS-DevTools/npm-publish@v4
123-
- with:
124-
- token: ${{ secrets.NPM_TOKEN }}
125-
```
103+
> If you're publishing a private package with [trusted publishing][], you will still need to provide a read-only [`token`][npm authentication token] so the action can read existing versions from the registry before publish.
104+
>
105+
> ```diff
106+
> - uses: JS-DevTools/npm-publish@v4
107+
> + with:
108+
> + token: ${{ secrets.NPM_TOKEN }}
109+
> ```
126110

127111
You can also publish to third-party registries. For example, to publish to the [GitHub Package Registry][], set `token` to `secrets.GITHUB_TOKEN` and `registry` to `https://npm.pkg.github.com`:
128112

@@ -138,8 +122,8 @@ jobs:
138122
contents: read
139123
packages: write # allow GITHUB_TOKEN to publish packages
140124
steps:
141-
- uses: actions/checkout@v5
142-
- uses: actions/setup-node@v5
125+
- uses: actions/checkout@v6
126+
- uses: actions/setup-node@v6
143127
with:
144128
node-version: "24"
145129
- run: npm ci
@@ -161,7 +145,7 @@ You can set any or all of the following input parameters using `with`:
161145

162146
| Name | Type | Default | Description |
163147
| ---------------- | ---------------------- | ----------------------------- | -------------------------------------------------------------------------------- |
164-
| `token` | string | unspecified | Registry authentication token, not required if using [trusted publishing][]³ |
148+
| `token` | string | None | Registry authentication token, not required if using [trusted publishing][]³ |
165149
| `registry`¹ | string | `https://registry.npmjs.org/` | Registry URL to use. |
166150
| `package` | string | Current working directory | Path to a package directory, a `package.json`, or a packed `.tgz` to publish. |
167151
| `tag`¹ | string | `latest` | [Distribution tag][npm-tag] to publish to. |
@@ -187,8 +171,6 @@ npm-publish exposes several output variables, which you can use in later steps o
187171
steps:
188172
- uses: JS-DevTools/npm-publish@v4
189173
+ id: publish
190-
with:
191-
token: ${{ secrets.NPM_TOKEN }}
192174
193175
+ - if: ${{ steps.publish.outputs.type }}
194176
+ run: echo "Version changed!"
@@ -237,7 +219,7 @@ import type { Options } from "@jsdevtools/npm-publish";
237219

238220
| Name | Type | Default | Description |
239221
| -------------------- | ---------------------- | ----------------------------- | -------------------------------------------------------------------------------- |
240-
| `token` | string | **required** | Registry authentication token, not required if using [trusted publishing][]³ |
222+
| `token` | string | None | Registry authentication token, not required if using [trusted publishing][]³ |
241223
| `registry`¹ | string, `URL` | `https://registry.npmjs.org/` | Registry URL to use. |
242224
| `package` | string | Current working directory | Path to a package directory, a `package.json`, or a packed `.tgz` to publish. |
243225
| `tag`¹ | string | `latest` | [Distribution tag][npm-tag] to publish to. |
@@ -246,7 +228,7 @@ import type { Options } from "@jsdevtools/npm-publish";
246228
| `strategy` | `all`, `upgrade` | `all` | Use `all` to publish all unique versions, `upgrade` for only semver upgrades. |
247229
| `ignoreScripts` | boolean | `true` | Run `npm publish` with the `--ignore-scripts` flag as a security precaution. |
248230
| `dryRun` | boolean | `false` | Run `npm publish` with the `--dry-run` flag to prevent publication. |
249-
| `logger` | object | `undefined` | Logging interface with `debug`, `info`, and `error` log methods. |
231+
| `logger` | object | None | Logging interface with `debug`, `info`, and `error` log methods. |
250232
| `temporaryDirectory` | string | `os.tmpdir()` | Temporary directory to hold a generated `.npmrc` file |
251233

252234
1. May be specified using `publishConfig` in `package.json`.
@@ -395,7 +377,7 @@ The `check-version` and `greater-version-only` boolean options were replaced wit
395377
`check-version: false` has been removed. If you only need to publish, without first checking whether the version exists in the registry, you can [use `npm` directly][publishing-nodejs-packages] instead:
396378

397379
```diff
398-
- uses: actions/setup-node@v5
380+
- uses: actions/setup-node@v6
399381
with:
400382
node-version: '24'
401383
+ registry-url: https://registry.npmjs.org/
@@ -447,7 +429,7 @@ If you can't change your build, you can set the `ignore-scripts` input to `false
447429
The global `.npmrc` file is no longer read nor modified. This means the `token` option is now required for the library and CLI. (It was already required for the action.) You may have workarounds in place referencing `INPUT_TOKEN`, which v1 [erroneously wrote][#15] to `.npmrc`. These workarounds should be removed.
448430

449431
```diff
450-
- uses: actions/setup-node@v5
432+
- uses: actions/setup-node@v6
451433
with:
452434
node-version: '24'
453435
registry-url: https://registry.npmjs.org/

0 commit comments

Comments
 (0)