-
Notifications
You must be signed in to change notification settings - Fork 253
39 lines (39 loc) · 1.75 KB
/
release.yml
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
name: Publish
on:
release:
types: [published]
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
# Set up .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
- run: npm ci
# Get the 'version' field out of the package.json file
- name: Get package.json version
id: package-json-version
run: echo "version=$(cat package.json | jq '.version' --raw-output)" >> $GITHUB_OUTPUT
# Abort if the version in the package.json file (prefixed with 'v') doesn't match the tag name of the release
- name: Check package.json version against tag name
if: format('v{0}', steps.package-json-version.outputs.version) != github.event.release.tag_name
uses: actions/github-script@v7
with:
script: core.setFailed('Release tag does not match package.json version!')
# Abort if this is a pre-release and the version in the package.json file doesn't contain a '-' to indicate that (e.g. v2.0.0-beta.1), or vice-versa
- name: Check package.json version against pre-release
if: contains(steps.package-json-version.outputs.version, '-') != github.event.release.prerelease
uses: actions/github-script@v7
with:
script: core.setFailed('Stability of release tag does not match package.json version!')
# If this is a pre-release, publish it to NPM under the 'next' tag (default is 'latest')
- run: npm publish --provenance ${{ github.event.release.prerelease && '--tag next' || '' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}