1
+ name : Publish Package
2
+
3
+ on :
4
+ push :
5
+ tags :
6
+ - ' v*'
7
+
8
+ jobs :
9
+ validate-version :
10
+ runs-on : ubuntu-latest
11
+ steps :
12
+ - uses : actions/checkout@v3
13
+
14
+ - name : Verify tag matches package version
15
+ run : |
16
+ TAG=${GITHUB_REF#refs/tags/v}
17
+ PKG_VERSION=$(node -p "require('./package.json').version")
18
+ if [ "$TAG" != "$PKG_VERSION" ]; then
19
+ echo "Tag $TAG doesn't match package version $PKG_VERSION"
20
+ exit 1
21
+ fi
22
+ echo "Version validation successful: $TAG"
23
+
24
+ build-and-publish :
25
+ needs : validate-version
26
+ runs-on : ubuntu-latest
27
+ steps :
28
+ - uses : actions/checkout@v3
29
+ with :
30
+ fetch-depth : 0
31
+
32
+ - name : Setup Node
33
+ uses : actions/setup-node@v3
34
+ with :
35
+ node-version : 18
36
+ registry-url : ' https://registry.npmjs.org'
37
+
38
+ - name : Setup pnpm
39
+ uses : pnpm/action-setup@v2
40
+ with :
41
+ version : 8.15.5
42
+ run_install : false
43
+
44
+ - name : Get pnpm store directory
45
+ shell : bash
46
+ run : |
47
+ echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
48
+
49
+ - name : Cache pnpm dependencies
50
+ uses : actions/cache@v3
51
+ with :
52
+ path : ${{ env.STORE_PATH }}
53
+ key : ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
54
+ restore-keys : |
55
+ ${{ runner.os }}-pnpm-store-
56
+
57
+ - name : Install dependencies
58
+ run : pnpm install --frozen-lockfile
59
+
60
+ - name : Typecheck
61
+ run : pnpm typecheck
62
+
63
+ - name : Lint
64
+ run : pnpm lint
65
+
66
+ - name : Build
67
+ run : pnpm build
68
+
69
+ - name : Test
70
+ run : pnpm test
71
+
72
+ - name : Publish package
73
+ run : |
74
+ echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
75
+ pnpm publish --no-git-checks --access public
76
+ env :
77
+ NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
78
+
79
+ - name : Create GitHub Release
80
+ run : gh release create ${GITHUB_REF#refs/tags/} --generate-notes
81
+ env :
82
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments