-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (60 loc) · 2.12 KB
/
Copy pathrelease.yml
File metadata and controls
72 lines (60 loc) · 2.12 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Release to npm
# Manual only. There is no push/tag trigger on purpose: publishing is
# irreversible (npm forbids re-using a version number, and unpublishing is
# restricted), so it should never happen as a side effect of a commit.
on:
workflow_dispatch:
inputs:
dry_run:
description: 'Pack and validate without publishing'
type: boolean
default: true
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: read
# Required for npm provenance, which attests that this tarball was built
# from this commit in this repository. Only works on a public repository.
id-token: write
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 22
cache: npm
registry-url: https://registry.npmjs.org
- run: npm ci
- name: Typecheck
run: npx tsc -p tsconfig.json --noEmit
- name: Test
run: npm test
- name: Refuse to publish a version that already exists
run: |
NAME=$(node -p "require('./package.json').name")
VERSION=$(node -p "require('./package.json').version")
echo "Preparing $NAME@$VERSION"
if npm view "$NAME@$VERSION" version >/dev/null 2>&1; then
echo "::error::$NAME@$VERSION is already published. Bump the version first."
exit 1
fi
- name: Check the README makes no false promises
run: |
if grep -q 'Not released yet' README.md; then
echo "::error::README still carries the pre-release note. Remove it before publishing."
exit 1
fi
- name: Pack (dry run)
if: inputs.dry_run
run: npm publish --dry-run
- name: Publish
if: ${{ !inputs.dry_run }}
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Tag the released commit
if: ${{ !inputs.dry_run }}
run: |
VERSION=$(node -p "require('./package.json').version")
git tag "v$VERSION"
git push origin "v$VERSION"