1
1
name : CI
2
2
3
3
on :
4
- pull_request :
4
+ push :
5
5
branches :
6
6
- main
7
- push :
7
+ pull_request :
8
8
branches :
9
9
- main
10
10
11
11
jobs :
12
- lint :
12
+ # Always use Node 20
13
+ # Add Node 18 to the matrix if we’re in the release PR
14
+ define-matrix :
15
+ runs-on : ubuntu-latest
16
+
17
+ outputs :
18
+ node-versions : ${{ steps.node-versions.outputs.node-versions }}
19
+
20
+ steps :
21
+ - name : Node version matrix
22
+ id : node-versions
23
+ run : |
24
+ if [ "${{ github.head_ref }}" == "changeset-release/main" ]; then
25
+ echo 'node-versions=[18, 20]' >> "$GITHUB_OUTPUT"
26
+ else
27
+ echo 'node-versions=[20]' >> "$GITHUB_OUTPUT"
28
+ fi
29
+ - name : Print Node version matrix
30
+ run : echo "node-versions=${{ steps.node-versions.outputs.node-versions }}"
31
+ - name : Check Node version matrix
32
+ run : |
33
+ if [ "${{ steps.node-versions.outputs.node-versions }}" != "[18, 20]" ] && [ "${{ steps.node-versions.outputs.node-versions }}" != "[20]" ]; then
34
+ echo "Node version matrix is not [18, 20] or [20]"
35
+ exit 1
36
+ fi
37
+
38
+ build :
39
+ runs-on : ubuntu-20.04
40
+ needs : define-matrix
41
+ strategy :
42
+ matrix :
43
+ node-version : ${{ fromJSON(needs.define-matrix.outputs.node-versions) }}
44
+
45
+ steps :
46
+ - uses : actions/checkout@v4
47
+ - uses : pnpm/action-setup@v4
48
+ - name : Use Node.js ${{ matrix.node-version }}
49
+ uses : actions/setup-node@v4
50
+ with :
51
+ node-version : ${{ matrix.node-version }}
52
+ cache : ' pnpm'
53
+ - name : Install dependencies
54
+ run : pnpm install
55
+ - name : Turborepo cache
56
+ uses : actions/cache@v4
57
+ with :
58
+ path : .turbo
59
+ key : turbo-${{ runner.os }}-node-${{ matrix.node-version }}
60
+ - name : Build
61
+ run : pnpm turbo build
62
+ - name : Update Turborepo cache
63
+ uses : actions/cache/save@v4
64
+ with :
65
+ path : .turbo
66
+ key : turbo-${{ runner.os }}-node-${{ matrix.node-version }}
67
+
68
+ format :
13
69
runs-on : ubuntu-20.04
14
70
strategy :
15
71
matrix :
16
72
node-version : [20]
17
73
74
+ steps :
75
+ - uses : actions/checkout@v4
76
+ - uses : pnpm/action-setup@v4
77
+ - name : Use Node.js ${{ matrix.node-version }}
78
+ uses : actions/setup-node@v4
79
+ with :
80
+ node-version : ${{ matrix.node-version }}
81
+ cache : ' pnpm'
82
+ - name : Install dev dependencies
83
+ run : pnpm install --dev
84
+ - name : Check code style
85
+ run : pnpm format:check
86
+
87
+ types :
88
+ runs-on : ubuntu-20.04
89
+ needs : [define-matrix, build]
90
+ strategy :
91
+ matrix :
92
+ node-version : ${{ fromJSON(needs.define-matrix.outputs.node-versions) }}
93
+
18
94
steps :
19
95
- uses : actions/checkout@v4
20
96
- uses : pnpm/action-setup@v4
@@ -26,8 +102,94 @@ jobs:
26
102
- name : Install dependencies
27
103
run : pnpm install
28
104
- name : Turborepo cache
29
- uses : dtinth/setup-github-actions-caching-for-turbo@v1
105
+ uses : actions/cache/restore@v4
106
+ with :
107
+ path : .turbo
108
+ key : turbo-${{ runner.os }}-node-${{ matrix.node-version }}
109
+ - name : Build
110
+ run : pnpm turbo build
111
+ - if : matrix.node-version == 20 || github.head_ref == 'changeset-release/main'
112
+ name : Check types
113
+ run : pnpm turbo types:check
114
+
115
+ test :
116
+ runs-on : ubuntu-20.04
117
+ needs : [define-matrix, build]
118
+ strategy :
119
+ matrix :
120
+ node-version : ${{ fromJSON(needs.define-matrix.outputs.node-versions) }}
121
+
122
+ steps :
123
+ - uses : actions/checkout@v4
124
+ - uses : pnpm/action-setup@v4
125
+ - name : Use Node.js ${{ matrix.node-version }}
126
+ uses : actions/setup-node@v4
127
+ with :
128
+ node-version : ${{ matrix.node-version }}
129
+ cache : ' pnpm'
130
+ - name : Install dependencies
131
+ run : pnpm install
132
+ - name : Turborepo cache
133
+ uses : actions/cache/restore@v4
134
+ with :
135
+ path : .turbo
136
+ key : turbo-${{ runner.os }}-node-${{ matrix.node-version }}
137
+ - name : Build
138
+ run : pnpm build
139
+ - name : Run tests
140
+ run : pnpm test
141
+
142
+ release :
143
+ if : github.ref == 'refs/heads/main'
144
+ runs-on : ubuntu-20.04
145
+ permissions :
146
+ contents : write
147
+ id-token : write
148
+ needs : [build, test]
149
+ strategy :
150
+ matrix :
151
+ node-version : [20]
152
+
153
+ steps :
154
+ - uses : actions/checkout@v4
155
+ - uses : pnpm/action-setup@v4
156
+ - name : Use Node.js ${{ matrix.node-version }}
157
+ uses : actions/setup-node@v4
158
+ with :
159
+ node-version : ${{ matrix.node-version }}
160
+ cache : ' pnpm'
161
+ - name : Install dependencies
162
+ run : pnpm install
163
+ - name : Turborepo cache
164
+ uses : actions/cache/restore@v4
165
+ with :
166
+ path : .turbo
167
+ key : turbo-${{ runner.os }}-node-${{ matrix.node-version }}
168
+ - name : Build
169
+ run : pnpm turbo build
170
+ - name : Git Status
171
+ run : git status
172
+ - name : Stash changes
173
+ run : git stash
174
+ - name : Create Release Pull Request or Publish to npm
175
+ id : changesets
176
+ uses : changesets/action@v1
30
177
with :
31
- cache-prefix : snippetz
32
- - name : Build & test
33
- run : pnpm turbo test
178
+ # The pull request title.
179
+ title : ' chore: release'
180
+ # The command to update version, edit CHANGELOG, read and delete changesets.
181
+ version : ' pnpm changeset version'
182
+ # The commit message to use.
183
+ commit : ' chore: version packages'
184
+ # The command to use to build and publish packages
185
+ publish : ' pnpm -r publish --access public'
186
+ env :
187
+ # https://github.com/settings/tokens/new
188
+ # Expiration: No expiration
189
+ # Select: repo.*
190
+ GITHUB_TOKEN : ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
191
+ # https://www.npmjs.com/settings/YOUR_ACCOUNT_HANDLE/tokens/granular-access-tokens/new
192
+ # Custom Expiration: 01-01-2100
193
+ # Permissions: Read and Write
194
+ # Select packages: @scalar
195
+ NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments