@@ -5,31 +5,67 @@ name: npm publish
5
5
6
6
on :
7
7
release :
8
- types : [created]
8
+ types : [published]
9
+
10
+ env :
11
+ TAG : ' ${{ github.event.release.tag_name }}'
9
12
10
13
jobs :
14
+ validate-release :
15
+ runs-on : ubuntu-latest
16
+ steps :
17
+ - name : Checkout code
18
+ uses : actions/checkout@v4
19
+ - name : Validate version tag pattern
20
+ run : |
21
+ if [[ ! "${{ env.TAG }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
22
+ echo "Version tag ${{ env.TAG }} invalid."
23
+ exit 1
24
+ fi
25
+ - name : Verify the tag is based off the main branch
26
+ run : |
27
+ if [[ "${{ github.event.release.target_commitish }}" != "main" ]]; then
28
+ echo "Release is not based on main branch but ${{ github.event.release.target_commitish }}"
29
+ exit 1
30
+ fi
31
+ - name : Make sure tag matches package.json version
32
+ run : |
33
+ PACKAGE_VERSION=$(node -e "console.log(require('./package.json').version);")
34
+ VERSION=$(echo "$TAG" | sed 's/v//g')
35
+ if [ "$PACKAGE_VERSION" != "$VERSION" ]; then
36
+ echo "Different versions between package.json ($PACKAGE_VERSION) and release tag ($VERSION)"
37
+ exit 1
38
+ fi
39
+
11
40
test :
12
41
runs-on : ubuntu-latest
42
+ needs : validate-release
13
43
steps :
14
44
- uses : actions/checkout@v4
15
45
- uses : actions/setup-node@v4
16
46
with :
17
- node-version : 20
47
+ node-version : 22
18
48
- run : npm ci
49
+ - run : npm run eslint
19
50
- run : npm test
20
51
21
52
build-and-publish :
22
- needs : test
23
53
runs-on : ubuntu-latest
54
+ needs : test
55
+ permissions :
56
+ contents : read
57
+ id-token : write
24
58
steps :
25
59
- uses : actions/checkout@v4
26
60
- uses : actions/setup-node@v4
27
61
with :
28
- node-version : 20
62
+ node-version : 22
29
63
registry-url : https://registry.npmjs.org/
30
64
cache : ' npm'
65
+ - run : npm install -g npm
31
66
- run : npm ci
32
67
- run : npm run build
33
- - run : npm publish
68
+ - name : Publish package
69
+ run : npm publish --provenance --tag ${{ github.event.release.prerelease && 'next' || 'latest' }}
34
70
env :
35
- NODE_AUTH_TOKEN : ${{secrets.NPM_SECRET}}
71
+ NODE_AUTH_TOKEN : ${{ secrets.NPM_SECRET }}
0 commit comments