-
Notifications
You must be signed in to change notification settings - Fork 56
285 lines (239 loc) · 9.36 KB
/
checks.yml
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
---
name: Checks
on: # yamllint disable-line rule:truthy
push:
branches:
- main
pull_request_target:
types:
- opened
- synchronize
merge_group:
env:
node_version: 23
jobs:
typecheck:
# Can run untrusted code so disable all permissions.
permissions: {}
name: Type Check Code Base
runs-on: ubuntu-latest
steps:
# This pattern is reused a couple of times.
# It's so verbose because of `pull_request_target`.
# For security reasons by deafult it won't check out the branch the PR is coming from.
- name: Checkout Branch
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 1
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.node_version }}
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: .npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- run: npm ci --cache .npm --prefer-offline
- name: Type Check
run: npm run typecheck
lint:
# Can run untrusted code so disable all permissions.
permissions: {}
name: Lint Code Base
runs-on: ubuntu-latest
steps:
- name: Checkout Branch
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 1
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.node_version }}
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: .npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- run: npm ci --cache .npm --prefer-offline
- name: Run Lints
run: npm run lint:ci
test:
# Can run untrusted code so disable all permissions.
permissions: {}
name: Test Code Base
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout Branch
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.head_ref }}
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 1
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: ${{ env.node_version }}
- name: Cache Node.js modules
uses: actions/cache@v4
with:
path: .npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- run: npm ci --cache .npm --prefer-offline
- name: Execute Tests
run: npm test -- --run --reporter github-actions --reporter=./.github/workflows/testsReporter.ts
- name: Upload Main Test Results
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: main-test-results
path: test-results/vitest-report.json
- name: Upload Test Results
if: always() && github.event_name == 'pull_request_target' && github.head_ref != 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: pr-test-results
path: test-results/vitest-report.json
checkCanMergeToMaintenance:
# Can run untrusted code so disable all permissions.
permissions: {}
name: Check Merge to Maintenance
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event.pull_request != null && !contains(github.event.pull_request.labels.*.name, 'breaking'))
outputs:
should_skip: ${{ steps.should_skip.outputs.should_skip }}
runs-on: ubuntu-latest
steps:
- uses: 8BitJonny/[email protected]
if: github.event.pull_request == null
id: PR
# Sets should_skip if this change wasn't made through a PR or if the PR is labeled as breaking.
- name: Check if should skip
id: should_skip
if: github.event.pull_request == null && (steps.PR.outputs.pr_found == 'false' || contains(steps.PR.outputs.pr_labels.*.name, 'breaking'))
run: |
echo "Skipping the rest of the job because this change wasn't made through a PR or the PR is labeled as breaking."
echo "should_skip=true" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
if: steps.should_skip.outputs.should_skip != 'true'
with:
ref: ${{ github.head_ref || github.ref }}
fetch-depth: 0
fetch-tags: false
- name: Check for conflicts with maintenance
if: steps.should_skip.outputs.should_skip != 'true'
run: |
git remote add upstream https://github.com/${{ github.repository }}
git fetch --no-tags upstream main maintenance
# This is its own command so that if the current branch is `maintenance` it'll be overridden.
git checkout -B maintenance upstream/maintenance
baseRef="${{github.head_ref}}"
before=""
if [[ $baseRef != "" ]]; then
before=$(git merge-base upstream/main "$baseRef")
else
before="${{ github.event.before }}"
fi
range="$before..${{ github.event.pull_request.head.sha || github.event.after }}"
echo "Checking if $range can be cherry-picked onto the maintenance branch."
git cherry-pick --allow-empty --no-commit -m 1 "$range" || (
echo "Merge conflicts detected with the maintenance branch!" && exit 1
)
- name: Install Node
if: steps.should_skip.outputs.should_skip != 'true'
uses: actions/setup-node@v4
with:
node-version: ${{ env.node_version }}
- name: Cache Node.js modules
if: steps.should_skip.outputs.should_skip != 'true'
uses: actions/cache@v4
with:
path: .npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- if: steps.should_skip.outputs.should_skip != 'true'
run: npm ci --cache .npm --prefer-offline
- name: Run Lints on maintenance
if: steps.should_skip.outputs.should_skip != 'true'
run: npm run lint:ci
- name: Type Check maintenance
if: steps.should_skip.outputs.should_skip != 'true'
run: npm run typecheck
mergeToMaintenance:
name: Merge To Maintenance
needs: [checkCanMergeToMaintenance]
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.checkCanMergeToMaintenance.outputs.should_skip != 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: false
- name: Cherry pick commits onto maintenance
run: |
git fetch origin maintenance:maintenance
git switch maintenance
# Commit using the GitHub Actions bot user.
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
range="${{ github.event.before }}..${{ github.event.after }}"
echo "Cherry picking $range onto the maintenance branch."
# Pick the freshly added commits onto the maintenance branch.
git cherry-pick --allow-empty -m 1 "$range" || (
echo "Merge conflicts detected with maintenance branch! This can only happen if there is a bug in checkCanMergeToMaintenance or mergeToMaintenance or someone pushed in between!" && exit 1
)
- name: Push changes
uses: ad-m/github-push-action@master
with:
branch: maintenance
github_token: ${{ secrets.GITHUB_TOKEN }}
reportTestResults:
name: Report Test Results
needs: [test]
runs-on: ubuntu-latest
if: github.event_name == 'pull_request_target' || (github.event_name == 'push' && github.event.pull_request != null)
steps:
# This must check out main.
# If it didn't someone could edit `postOrUpdateTestsReport.js` to easily run arbitrary code.
- uses: actions/checkout@v4
with:
ref: refs/heads/main
fetch-depth: 1
- name: Download Main Test Results
uses: dawidd6/action-download-artifact@v7
with:
branch: main
name: main-test-results
path: main-test-results
- name: Download Test Results
uses: actions/download-artifact@v4
with:
name: pr-test-results
path: pr-test-results
- name: Post or Update Report
uses: actions/github-script@v7
with:
script: |
const { default: postOrUpdateTestsReport } = await import("/home/runner/work/foundry-vtt-types/foundry-vtt-types/.github/workflows/postOrUpdateTestsReport.js");
await postOrUpdateTestsReport({ github, context, core });
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}