Repository navigation
50 lines (47 loc) · 1.64 KB
/
Copy pathrelease.yml
File metadata and controls
50 lines (47 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
name: Release
# Publishing a GitHub release tagged v<version> publishes that version to npm.
# npm trusts this workflow through OIDC (trusted publishing), so the repository
# holds no npm token, and npm attaches a provenance statement to the package.
on:
release:
types: [published]
permissions:
contents: read
jobs:
publish:
name: Publish to npm
runs-on: ubuntu-latest
permissions:
contents: read
# Lets the job request the OIDC token npm exchanges for a publish token.
id-token: write
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
cache: npm
# Trusted publishing needs npm 11.5.1 or later.
- run: npm install --global npm@latest
- name: Check the tag matches package.json
env:
TAG: ${{ github.event.release.tag_name }}
run: |
version=$(node -p "require('./package.json').version")
if [ "$TAG" != "v$version" ]; then
echo "::error::The release tag $TAG does not match package.json version $version (expected v$version)."
exit 1
fi
- run: npm ci
- run: npm run build
- run: npm run typecheck
- run: npm test
- name: Publish
env:
PRERELEASE: ${{ github.event.release.prerelease }}
run: |
# A prerelease goes to the `next` dist-tag, so `npm install` keeps
# resolving to the latest stable version.
if [ "$PRERELEASE" = "true" ]; then tag=next; else tag=latest; fi
npm publish --access public --tag "$tag"