Skip to content

Commit d0b294f

Browse files
authored
docs: Update Node.js builder docs (#2282)
- Adds a "known issues" section. - Adds instructions on how to custom publish without using the `publish` action. Related #2322 --------- Signed-off-by: Ian Lewis <[email protected]>
1 parent 2be2c25 commit d0b294f

File tree

1 file changed

+98
-9
lines changed

1 file changed

+98
-9
lines changed

internal/builders/nodejs/README.md

Lines changed: 98 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ workflow the "Node.js builder" from now on.
1818
- [Development status](#development-status)
1919
- [Generating Provenance](#generating-provenance)
2020
- [Getting Started](#getting-started)
21+
- [Publishing packages](#publishing-packages)
22+
- [Using the `nodejs/publish` action](#using-the-nodejspublish-action)
23+
- [Custom publishing](#custom-publishing)
2124
- [Referencing the Node.js builder](#referencing-the-nodejs-builder)
2225
- [Private Repositories](#private-repositories)
2326
- [Supported Triggers](#supported-triggers)
@@ -28,6 +31,9 @@ workflow the "Node.js builder" from now on.
2831
- [Verification](#verification)
2932
- [npm audit signatures](#npm-audit-signatures)
3033
- [slsa-verifier](#slsa-verifier)
34+
- [Known issues](#known-issues)
35+
- [Workspaces are not supported](#workspaces-are-not-supported)
36+
- [Other package managers not supported](#other-package-managers-not-supported)
3137

3238
<!-- tocstop -->
3339

@@ -47,8 +53,8 @@ tampered with.
4753

4854
The Node.js builder is currently in beta. The API could change while approaching
4955
a Generally Available (GA) release. You can track progress towards General
50-
Availability via
51-
[this milestone](https://github.com/slsa-framework/slsa-github-generator/milestone/17).
56+
Availability via the
57+
[Node.js Builder GA milestone](https://github.com/slsa-framework/slsa-github-generator/milestone/17).
5258

5359
Please try it out and
5460
[create an issue](https://github.com/slsa-framework/slsa-github-generator/issues/new)
@@ -128,6 +134,10 @@ they are listed.
128134
Once the build scripts are run, the Node.js builder creates a package tarball
129135
and provenance attestation which are uploaded as artifacts to the workflow run.
130136

137+
### Publishing packages
138+
139+
#### Using the `nodejs/publish` action
140+
131141
After creating the package you can publish the package using the provided
132142
`nodejs/publish` action.
133143

@@ -144,7 +154,7 @@ publish:
144154
145155
- name: publish
146156
id: publish
147-
uses: slsa-framework/slsa-github-generator/actions/nodejs/publish@<git sha> # v1.6.0
157+
uses: slsa-framework/slsa-github-generator/actions/nodejs/publish@e55b76ce421082dfa4b34a6ac3c5e59de0f3bb58 # v1.7.0
148158
with:
149159
access: public
150160
node-auth-token: ${{ secrets.NPM_TOKEN }}
@@ -160,6 +170,54 @@ This action downloads the package tarball and provenance before running `npm
160170
publish` to publish your package to the npm registry. We provide a
161171
`node-auth-token` so that we can authenticate with `npmjs.com`.
162172

173+
#### Custom publishing
174+
175+
After the package has been built you can publish on your own by downloading the
176+
package archive and provenance attestations and running your own custom
177+
publishing command.
178+
179+
Here is an example:
180+
181+
```yaml
182+
jobs:
183+
# build job etc. ...
184+
185+
publish:
186+
needs: [build]
187+
runs-on: ubuntu-latest
188+
steps:
189+
- name: Setup Node
190+
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3.7.0
191+
with:
192+
node-version: 18
193+
registry-url: "https://registry.npmjs.org"
194+
195+
- name: Download tarball
196+
uses: slsa-framework/slsa-github-generator/actions/nodejs/[email protected]
197+
with:
198+
name: ${{ needs.build.outputs.package-download-name }}
199+
path: ${{ needs.build.outputs.package-name }}
200+
sha256: ${{ needs.build.outputs.package-download-sha256 }}
201+
202+
- name: Download provenance
203+
uses: slsa-framework/slsa-github-generator/actions/nodejs/[email protected]
204+
with:
205+
name: ${{ needs.build.outputs.provenance-download-name }}
206+
path: "attestations"
207+
sha256: ${{ needs.build.outputs.provenance-download-sha256 }}
208+
209+
- name: Publish the package
210+
env:
211+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
212+
TARBALL_PATH: "${{ needs.build.outputs.package-name }}"
213+
PROVENANCE_PATH: "./attestations/${{ needs.build.outputs.provenance-name }}"
214+
run: |
215+
npm publish "${TARBALL_PATH}" --access=public --provenance-file="${PROVENANCE_PATH}"
216+
```
217+
218+
You will need a package management tool that supports providing the provenance
219+
file. Currently [npm], [lerna] or [pnpm] can support this.
220+
163221
### Referencing the Node.js builder
164222

165223
At present, the builder **MUST** be referenced by a tag of the form `@vX.Y.Z`,
@@ -173,7 +231,7 @@ renovatebot, see the main repository [README.md](../../../README.md).
173231

174232
Private repositories are supported with some caveats. Currently all builds
175233
generate and post a new entry in the public
176-
[Rekor](https://github.com/sigstore/rekor) API server instance at
234+
[Rekor] API server instance at
177235
https://rekor.sigstore.dev/. This entry includes the repository name. This will cause the
178236
private repository name to leak and be discoverable via the public Rekor API
179237
server.
@@ -227,7 +285,7 @@ Inputs:
227285
| node-version | No | | The version of Node.js to use. If no value is supplied, the `node` version from `$PATH` is used. |
228286
| node-version-file | No | | File containing the version Spec of the version to use. Examples: .nvmrc, .node-version, .tool-versions. |
229287
| rekor-log-public | No | false | Set to true to opt-in to posting to the public transparency log. Will generate an error if false for private repositories. This input has no effect for public repositories. See [Private Repositories](#private-repositories).<br>Default: `false` |
230-
| run-scripts | No | | A comma separated ordered list of npm scripts to run before running `npm publish`. See [scripts](https://docs.npmjs.com/cli/v9/using-npm/scripts) for more information. \ |
288+
| run-scripts | No | | A comma separated ordered list of npm scripts to run before running `npm publish`. See [scripts] for more information. \ |
231289

232290
### Workflow Outputs
233291

@@ -244,12 +302,12 @@ The Node.js builder produces the following outputs:
244302

245303
### Provenance Format
246304

247-
Provenance is generated as an [in-toto](https://in-toto.io/) statement with a
305+
Provenance is generated as an [in-toto] statement with a
248306
SLSA v0.2 predicate.
249307

250-
| Name | Value | Description |
251-
| -------------- | -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
252-
| `subject.name` | Package url ([purl](https://github.com/package-url/purl-spec)) | The subject identifies the package in [purl](https://github.com/package-url/purl-spec) format. |
308+
| Name | Value | Description |
309+
| -------------- | -------------------- | ---------------------------------------------------- |
310+
| `subject.name` | Package url ([purl]) | The subject identifies the package in [purl] format. |
253311

254312
The project generates SLSA v0.2 provenance predicate with the following values.
255313

@@ -374,3 +432,34 @@ package name, and package version.
374432

375433
Please see the [documentation](https://github.com/slsa-framework/slsa-verifier)
376434
for more information.
435+
436+
### Known issues
437+
438+
#### Workspaces are not supported
439+
440+
[Workspaces] are currently not supported but will be supported in a future
441+
release. See
442+
[#1789](https://github.com/slsa-framework/slsa-github-generator/issues/1789) for
443+
more details.
444+
445+
#### Other package managers not supported
446+
447+
Currently the Node.js builder does not support using other package managers like
448+
[yarn], [pnpm], or [lerna] for building.
449+
450+
Currently [lerna] and [pnpm] can support publishing. See
451+
[Custom publishing](#custom-publishing) for more details.
452+
453+
[Yarn] implements publishing on it's own and requires support for the
454+
`provenance` and `provenaceFile` config options. See
455+
[yarnpkg/berry#5430](https://github.com/yarnpkg/berry/issues/5430).
456+
457+
[in-toto]: https://in-toto.io/
458+
[rekor]: https://github.com/sigstore/rekor
459+
[purl]: https://github.com/package-url/purl-spec
460+
[scripts]: https://docs.npmjs.com/cli/v9/using-npm/scripts
461+
[workspaces]: https://docs.npmjs.com/cli/v9/using-npm/workspaces
462+
[npm]: https://www.npmjs.com/package/npm
463+
[yarn]: https://yarnpkg.com/
464+
[pnpm]: https://pnpm.io/
465+
[lerna]: https://lerna.js.org/

0 commit comments

Comments
 (0)