Skip to content

Commit fc80b61

Browse files
committed
docs(readme): switch main example to trusted publishing
1 parent 89cf006 commit fc80b61

File tree

1 file changed

+28
-33
lines changed

1 file changed

+28
-33
lines changed

README.md

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ jobs:
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,6 +86,9 @@ on:
8886
jobs:
8987
publish:
9088
runs-on: ubuntu-latest
89+
permissions:
90+
contents: read
91+
id-token: write
9192
steps:
9293
- uses: actions/checkout@v5
9394
- uses: actions/setup-node@v5
@@ -96,33 +97,29 @@ jobs:
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+
> jobs:
107+
> publish:
108+
> runs-on: ubuntu-latest
109+
> permissions:
110+
> contents: read
111+
> id-token: write # required to use OIDC
112+
> steps:
113+
> - uses: actions/checkout@v5
114+
> - uses: actions/setup-node@v5
115+
> with:
116+
> node-version: "24" # includes npm@11.6.0
117+
> - run: npm ci
118+
> - run: npm test
119+
> - uses: JS-DevTools/npm-publish@v4
120+
> - with:
121+
> - token: ${{ secrets.NPM_TOKEN }}
122+
> ```
126123

127124
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`:
128125

@@ -161,7 +158,7 @@ You can set any or all of the following input parameters using `with`:
161158

162159
| Name | Type | Default | Description |
163160
| ---------------- | ---------------------- | ----------------------------- | -------------------------------------------------------------------------------- |
164-
| `token` | string | unspecified | Registry authentication token, not required if using [trusted publishing][]³ |
161+
| `token` | string | None | Registry authentication token, not required if using [trusted publishing][]³ |
165162
| `registry`¹ | string | `https://registry.npmjs.org/` | Registry URL to use. |
166163
| `package` | string | Current working directory | Path to a package directory, a `package.json`, or a packed `.tgz` to publish. |
167164
| `tag`¹ | string | `latest` | [Distribution tag][npm-tag] to publish to. |
@@ -187,8 +184,6 @@ npm-publish exposes several output variables, which you can use in later steps o
187184
steps:
188185
- uses: JS-DevTools/npm-publish@v4
189186
+ id: publish
190-
with:
191-
token: ${{ secrets.NPM_TOKEN }}
192187
193188
+ - if: ${{ steps.publish.outputs.type }}
194189
+ run: echo "Version changed!"
@@ -237,7 +232,7 @@ import type { Options } from "@jsdevtools/npm-publish";
237232

238233
| Name | Type | Default | Description |
239234
| -------------------- | ---------------------- | ----------------------------- | -------------------------------------------------------------------------------- |
240-
| `token` | string | **required** | Registry authentication token, not required if using [trusted publishing][]³ |
235+
| `token` | string | None | Registry authentication token, not required if using [trusted publishing][]³ |
241236
| `registry`¹ | string, `URL` | `https://registry.npmjs.org/` | Registry URL to use. |
242237
| `package` | string | Current working directory | Path to a package directory, a `package.json`, or a packed `.tgz` to publish. |
243238
| `tag`¹ | string | `latest` | [Distribution tag][npm-tag] to publish to. |
@@ -246,7 +241,7 @@ import type { Options } from "@jsdevtools/npm-publish";
246241
| `strategy` | `all`, `upgrade` | `all` | Use `all` to publish all unique versions, `upgrade` for only semver upgrades. |
247242
| `ignoreScripts` | boolean | `true` | Run `npm publish` with the `--ignore-scripts` flag as a security precaution. |
248243
| `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. |
244+
| `logger` | object | None | Logging interface with `debug`, `info`, and `error` log methods. |
250245
| `temporaryDirectory` | string | `os.tmpdir()` | Temporary directory to hold a generated `.npmrc` file |
251246

252247
1. May be specified using `publishConfig` in `package.json`.

0 commit comments

Comments
 (0)