Skip to content

Commit bd017c9

Browse files
authored
Add example for publishing with GitLab provenance (npm#684)
Also code blocks in that document were tagged with their language to provide syntax highlighting.
1 parent db37a94 commit bd017c9

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

content/packages-and-modules/securing-your-code/generating-provenance-statements.mdx

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,55 +49,72 @@ To update your GitHub Actions workflow to publish your packages with provenance,
4949

5050
- Give permission to mint an ID-token:
5151

52-
```
52+
```yaml
5353
permissions:
5454
id-token: write
5555
```
5656
5757
- Run on a [GitHub-hosted runner](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources):
5858
59-
```
59+
```yaml
6060
runs-on: ubuntu-latest
6161
```
6262
6363
- Add the `--provenance` flag to your publish command:
6464

65-
```
65+
```sh
6666
npm publish --provenance
6767
```
6868

6969
- If you are publishing a package for the first time you will also need to explicitly set access to public:
7070

71-
```
71+
```sh
7272
npm publish --provenance --access public
7373
```
7474

7575
### Example GitHub Actions workflow
7676

7777
This example workflow publishes a package to the npm registry with provenance.
7878

79-
```
79+
```yaml
8080
name: Publish Package to npmjs
8181
on:
82-
release:
83-
types: [created]
82+
release:
83+
types: [created]
8484
jobs:
85-
build:
86-
runs-on: ubuntu-latest
87-
permissions:
88-
contents: read
89-
id-token: write
90-
steps:
91-
- uses: actions/checkout@v3
92-
- uses: actions/setup-node@v3
93-
with:
94-
node-version: '18.x'
95-
registry-url: 'https://registry.npmjs.org'
96-
- run: npm install -g npm
97-
- run: npm ci
98-
- run: npm publish --provenance --access public
99-
env:
100-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
85+
build:
86+
runs-on: ubuntu-latest
87+
permissions:
88+
contents: read
89+
id-token: write
90+
steps:
91+
- uses: actions/checkout@v3
92+
- uses: actions/setup-node@v3
93+
with:
94+
node-version: '18.x'
95+
registry-url: 'https://registry.npmjs.org'
96+
- run: npm install -g npm
97+
- run: npm ci
98+
- run: npm publish --provenance --access public
99+
env:
100+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
101+
```
102+
103+
### Example GitLab CI job
104+
105+
This example job publishes a package to the npm registry with provenance when a git tag is pushed. Don’t forget to define the `NPM_TOKEN` variable in your GitLab project settings.
106+
107+
```yaml
108+
publish:
109+
image: 'node:20'
110+
rules:
111+
- if: $CI_COMMIT_TAG
112+
id_tokens:
113+
SIGSTORE_ID_TOKEN:
114+
aud: sigstore
115+
script:
116+
- npm config set //registry.npmjs.org/:_authToken "$NPM_TOKEN"
117+
- npm publish --provenance --access publich
101118
```
102119

103120
### Using third-party package publishing tools

0 commit comments

Comments
 (0)