-
Notifications
You must be signed in to change notification settings - Fork 3
59 lines (49 loc) · 1.54 KB
/
Copy pathpublish-npm.yml
File metadata and controls
59 lines (49 loc) · 1.54 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
name: Publish npm package
on:
release:
types:
- published
workflow_dispatch:
inputs:
release_tag:
description: "Tag to publish (must match package.json version, e.g. v0.0.1)"
required: false
type: string
jobs:
publish:
if: github.event_name == 'workflow_dispatch' || github.event.release.prerelease == false
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Ensure tag matches package version
run: |
EVENT_NAME="${{ github.event_name }}"
VERSION="$(node -p "JSON.parse(require('node:fs').readFileSync('package.json', 'utf8')).version")"
if [ "$EVENT_NAME" = "release" ]; then
RAW_TAG="${GITHUB_REF_NAME}"
else
RAW_TAG="${{ github.event.inputs.release_tag }}"
if [ -z "$RAW_TAG" ]; then
RAW_TAG="v$VERSION"
fi
fi
TAG="${RAW_TAG#v}"
if [ "$TAG" != "$VERSION" ]; then
echo "Release tag must be v$VERSION, got ${RAW_TAG}."
exit 1
fi
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org
- name: Verify publish contents
run: npm pack --dry-run
- name: Publish to npm
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}