Skip to content

Commit 37f1286

Browse files
committed
Publish releases to npm as a trusted publisher
npm has recently limited the lifetime of all access tokens to 90 days (https://gh.io/npm-token-changes), so it would be a bit inconvenient to stick to our current access token-based method of publishing releases. Meanwhile npm has implemented a more secure publishing method based on OIDC in which you tell the registry that a particular GitHub Actions workflow should be a "trusted publisher" for a given package, and then the CLI will authenticate automatically. (https://docs.npmjs.com/trusted-publishers) I've already set it up on the registry side. Let's see if this works next time we release.
1 parent 326eb12 commit 37f1286

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

.github/workflows/release.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ on:
1313
- major
1414
concurrency: release
1515
permissions:
16-
contents: write
16+
id-token: write # Allow npm to authenticate as a trusted publisher
17+
contents: write # Allow creating a release
1718
jobs:
1819
release:
1920
name: "Release & Publish"
@@ -44,16 +45,15 @@ jobs:
4445
run: yarn build
4546

4647
- name: 🚀 Publish to npm
47-
id: npm-publish
48-
uses: JS-DevTools/npm-publish@v3
49-
with:
50-
token: ${{ secrets.NPM_TOKEN }}
51-
access: public
48+
# We use npm since Yarn Classic doesn't support trusted publishing
49+
run: |
50+
npm publish --provenance --ignore-scripts
51+
echo "VERSION=$(jq '.version' --raw-output package.json)" >> "$GITHUB_ENV"
5252
5353
- name: 🧬 Create release
5454
uses: softprops/action-gh-release@v2
5555
with:
56-
tag_name: v${{ steps.npm-publish.outputs.version }}
57-
body: ${{ steps.npm-publish.outputs.version }} Release
56+
tag_name: v${{ env.VERSION }}
57+
body: ${{ env.VERSION }} Release
5858
draft: false
5959
prerelease: false

0 commit comments

Comments
 (0)