-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (60 loc) · 1.9 KB
/
publish.yml
File metadata and controls
72 lines (60 loc) · 1.9 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: Publish
on:
release:
types:
- published
permissions:
contents: read
id-token: write
jobs:
publish:
name: Publish package to npm
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: 24
registry-url: https://registry.npmjs.org
cache: npm
- name: Upgrade npm for trusted publishing
run: npm install --global npm@latest
- name: Show runtime versions
run: |
node --version
npm --version
- name: Install dependencies
run: npm ci
- name: Verify release tag matches package version
run: |
node --input-type=module -e "
import { readFileSync } from 'node:fs';
const pkg = JSON.parse(readFileSync('package.json', 'utf8'));
const expected = 'v' + pkg.version;
const actual = process.env.RELEASE_TAG;
if (actual !== expected) {
console.error('Release tag mismatch:', { actual, expected });
process.exit(1);
}
"
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
- name: Build
run: npm run build
- name: Test
run: npm test
- name: Select npm dist-tag
id: publish_meta
run: |
VERSION=$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).version")
if [[ "$VERSION" == *-* ]]; then
echo "dist_tag=next" >> "$GITHUB_OUTPUT"
echo "publish_args=--provenance --tag next" >> "$GITHUB_OUTPUT"
else
echo "dist_tag=latest" >> "$GITHUB_OUTPUT"
echo "publish_args=--provenance" >> "$GITHUB_OUTPUT"
fi
- name: Publish to npm
run: npm publish ${{ steps.publish_meta.outputs.publish_args }}