Skip to content

Commit b4ef5fa

Browse files
Publish to npm via trusted publishing (#30)
Replaces the NPM_TOKEN secret with OIDC, so there is no long-lived publishing credential in the repository. We're trying a separate job to limit the scope of the token but need to check this works in practice.
1 parent e2e77a7 commit b4ef5fa

1 file changed

Lines changed: 32 additions & 12 deletions

File tree

.github/workflows/build.yml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,50 @@ on:
55
push:
66
branches:
77
- '**'
8+
env:
9+
# renovate: datasource=npm depName=npm
10+
NPM_VERSION: '11'
11+
812
jobs:
913
build:
1014
runs-on: ubuntu-latest
1115
permissions:
1216
contents: read
13-
packages: write
1417
steps:
1518
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
1619
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
1720
with:
1821
node-version: '24.x'
19-
registry-url: 'https://registry.npmjs.org'
2022
cache: npm
21-
- run: npm install -g npm@11 --registry=https://registry.npmjs.org
23+
- run: npm install -g npm@${{ env.NPM_VERSION }} --registry=https://registry.npmjs.org
2224
- uses: microbit-foundation/npm-package-versioner-action@v3
2325
- run: npm ci
24-
env:
25-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2626
- run: npm run ci
27-
- name: Upload GitHub packages artifact
28-
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5
27+
- run: npm pack
28+
if: github.event_name == 'release'
29+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
30+
if: github.event_name == 'release'
31+
with:
32+
name: npm-tarball
33+
path: '*.tgz'
34+
if-no-files-found: error
35+
retention-days: 1
36+
37+
publish:
38+
needs: build
39+
if: github.event_name == 'release'
40+
runs-on: ubuntu-latest
41+
environment: npm-publish
42+
permissions:
43+
contents: read
44+
id-token: write
45+
steps:
46+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
47+
with:
48+
name: npm-tarball
49+
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
2950
with:
30-
path: ./storybook-static
31-
- run: npm publish --allow-directory=all
32-
if: github.event_name == 'release' && github.event.action == 'created'
33-
env:
34-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
51+
node-version: '24.x'
52+
registry-url: 'https://registry.npmjs.org'
53+
- run: npm install -g npm@${{ env.NPM_VERSION }} --registry=https://registry.npmjs.org
54+
- run: npm stage publish --allow-file=all ./*.tgz

0 commit comments

Comments
 (0)