Skip to content

Commit 801dba2

Browse files
Publish to npm via trusted publishing
Replaces the NPM_TOKEN secret with OIDC, following makecode-embed. The build job packs the tarball and a separate publish job, with no checkout and the only id-token permission, stages it to npm from the npm-publish environment. npm pack now runs on every build so packaging problems fail a branch build rather than a release.
1 parent a411034 commit 801dba2

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

.github/workflows/build.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ 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
@@ -15,12 +19,34 @@ jobs:
1519
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
1620
with:
1721
node-version: '24.x'
18-
registry-url: 'https://registry.npmjs.org'
1922
cache: npm
20-
- 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
2124
- run: npm ci
2225
- run: npm run ci
23-
- run: npm publish --allow-directory=all
24-
if: github.event_name == 'release' && github.event.action == 'created'
25-
env:
26-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
26+
- run: npm pack
27+
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
28+
if: github.event_name == 'release'
29+
with:
30+
name: npm-tarball
31+
path: '*.tgz'
32+
if-no-files-found: error
33+
retention-days: 1
34+
35+
publish:
36+
needs: build
37+
if: github.event_name == 'release'
38+
runs-on: ubuntu-latest
39+
environment: npm-publish
40+
permissions:
41+
contents: read
42+
id-token: write
43+
steps:
44+
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
45+
with:
46+
name: npm-tarball
47+
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
48+
with:
49+
node-version: '24.x'
50+
registry-url: 'https://registry.npmjs.org'
51+
- run: npm install -g npm@${{ env.NPM_VERSION }} --registry=https://registry.npmjs.org
52+
- run: npm stage publish --allow-file=all ./*.tgz

0 commit comments

Comments
 (0)