forked from Homebrew/homebrew-core
-
Notifications
You must be signed in to change notification settings - Fork 0
563 lines (496 loc) · 22.5 KB
/
tests.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
name: CI
on:
push:
branches:
- master
pull_request:
merge_group:
env:
HOMEBREW_DEVELOPER: 1
HOMEBREW_GITHUB_ACTIONS: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_FROM_API: 1
GH_REPO: ${{github.repository}}
GH_NO_UPDATE_NOTIFIER: 1
GH_PROMPT_DISABLED: 1
concurrency:
group: "tests-${{ github.ref }}"
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
tap_syntax:
if: github.repository_owner == 'Homebrew'
runs-on: ubuntu-22.04
container:
image: ghcr.io/homebrew/ubuntu22.04:master
env:
HOMEBREW_SIMULATE_MACOS_ON_LINUX: 1
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- run: brew test-bot --only-tap-syntax
- name: Dump merge_group env
if: github.event_name != 'pull_request'
run: |
echo '```' >> "$GITHUB_STEP_SUMMARY"
env | grep -Eiv 'token|key|secret' | tee -a "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
- name: Show contents of `GITHUB_EVENT_PATH`
run: |
echo '```' >> "$GITHUB_STEP_SUMMARY"
jq . < "$GITHUB_EVENT_PATH" | tee -a "$GITHUB_STEP_SUMMARY"
echo '```' >> "$GITHUB_STEP_SUMMARY"
formulae_detect:
if: github.repository_owner == 'Homebrew' && github.event_name != 'push'
runs-on: ubuntu-22.04
container:
image: ghcr.io/homebrew/ubuntu22.04:master
outputs:
testing_formulae: ${{ steps.formulae-detect.outputs.testing_formulae }}
added_formulae: ${{ steps.formulae-detect.outputs.added_formulae }}
deleted_formulae: ${{ steps.formulae-detect.outputs.deleted_formulae }}
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- run: brew test-bot --only-formulae-detect
id: formulae-detect
- name: Fetch detected formulae bottles
if: >
github.event_name == 'merge_group' ||
contains(github.event.pull_request.labels.*.name, 'CI-published-bottle-commits')
env:
TESTING_FORMULAE: ${{ steps.formulae-detect.outputs.testing_formulae }}
run: brew test-bot --only-bottles-fetch --testing-formulae="$TESTING_FORMULAE"
setup_tests:
permissions:
pull-requests: read
if: github.repository_owner == 'Homebrew' && github.event_name == 'pull_request'
runs-on: ubuntu-22.04
needs: formulae_detect
outputs:
syntax-only: ${{ steps.check-labels.outputs.syntax-only }}
linux-runner: ${{ steps.check-labels.outputs.linux-runner }}
logs-dir: ${{ steps.check-labels.outputs.logs-dir }}
fail-fast: ${{ steps.check-labels.outputs.fail-fast }}
test-dependents: ${{ steps.check-labels.outputs.test-dependents }}
timeout-minutes: ${{ steps.check-labels.outputs.timeout-minutes }}
test-bot-formulae-args: ${{ steps.check-labels.outputs.test-bot-formulae-args }}
test-bot-dependents-args: ${{ steps.check-labels.outputs.test-bot-dependents-args }}
cleanup-linux-runner: ${{ steps.check-labels.outputs.cleanup-linux-runner }}
steps:
- name: Check for CI labels
id: check-labels
uses: actions/github-script@v6
env:
TESTING_FORMULAE: ${{needs.formulae_detect.outputs.testing_formulae}}
ADDED_FORMULAE: ${{needs.formulae_detect.outputs.added_formulae}}
DELETED_FORMULAE: ${{needs.formulae_detect.outputs.deleted_formulae}}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: { labels: labels } } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
const label_names = labels.map(label => label.name)
var syntax_only = false
if (label_names.includes('CI-syntax-only')) {
console.log('CI-syntax-only label found. Skipping tests job.')
syntax_only = true
} else {
console.log('No CI-syntax-only label found. Running tests job.')
}
if (label_names.includes('CI-published-bottle-commits')) {
console.log('CI-published-bottle-commits label found. Skipping tests job.')
syntax_only = true
}
core.setOutput('syntax-only', syntax_only)
if (syntax_only) {
return
}
if (label_names.includes('CI-linux-self-hosted')) {
core.setOutput('linux-runner', 'linux-self-hosted-1')
core.setOutput('cleanup-linux-runner', 'true')
} else {
if (label_names.includes('CI-linux-large-runner')) {
core.setOutput('linux-runner', 'homebrew-large-bottle-build')
} else {
core.setOutput('linux-runner', 'ubuntu-22.04')
}
core.setOutput('logs-dir', '/github/home/.cache/Homebrew/Logs')
core.setOutput('cleanup-linux-runner', 'false')
}
if (label_names.includes('CI-no-fail-fast')) {
console.log('CI-no-fail-fast label found. Continuing tests despite failing matrix builds.')
core.setOutput('fail-fast', 'false')
} else {
console.log('No CI-no-fail-fast label found. Stopping tests on first failing matrix build.')
core.setOutput('fail-fast', 'true')
}
if (label_names.includes('CI-skip-dependents')) {
console.log('CI-skip-dependents label found. Skipping brew test-bot --only-formulae-dependents.')
core.setOutput('test-dependents', 'false')
} else if (!process.env.TESTING_FORMULAE) {
console.log('No testing formulae found. Skipping brew test-bot --only-formulae-dependents.')
core.setOutput('test-dependents', 'false')
} else {
console.log('No CI-skip-dependents label found. Running brew test-bot --only-formulae-dependents.')
core.setOutput('test-dependents', 'true')
}
const maximum_long_pr_count = 2
if (label_names.includes('CI-long-timeout')) {
const labelCountQuery = `query($owner:String!, $name:String!, $label:String!) {
repository(owner:$owner, name:$name) {
pullRequests(last: 100, states: OPEN, labels: [$label]) {
totalCount
}
}
}`;
var long_pr_count;
try {
const response = await github.graphql(
labelCountQuery, {
owner: context.repo.owner,
name: context.repo.repo,
label: 'CI-long-timeout'
}
)
long_pr_count = response.repository.pullRequests.totalCount
} catch (error) {
// The GitHub API query errored, so fail open and assume 0 long PRs.
long_pr_count = 0
core.warning('CI-long-timeout label count query failed. Assuming no long PRs.')
}
if (long_pr_count > maximum_long_pr_count) {
core.setFailed(`Too many pull requests (${long_pr_count}) with the long-timeout label!`)
core.error(`Only ${maximum_long_pr_count} pull requests at a time can use this label.`)
core.error('Remove the long-timeout label from this or other PRs (once their CI has completed).')
}
console.log('CI-long-timeout label found. Setting long GitHub Actions timeout.')
core.setOutput('timeout-minutes', '4320')
} else {
console.log('No CI-long-timeout label found. Setting short GitHub Actions timeout.')
core.setOutput('timeout-minutes', '90')
if (label_names.includes('long build')) {
core.setFailed('PR requires the CI-long-timeout label but it is not set!')
core.error('If the longer timeout is not required, remove the "long build" label.')
core.error('Otherwise, add the "CI-long-timeout" label.')
core.error(`No more than ${maximum_long_pr_count} PRs at a time may use "CI-long-timeout".`)
}
}
const test_bot_formulae_args = ["--only-formulae", "--junit", "--only-json-tab", "--skip-dependents"]
test_bot_formulae_args.push(`--testing-formulae="${process.env.TESTING_FORMULAE}"`)
test_bot_formulae_args.push(`--added-formulae="${process.env.ADDED_FORMULAE}"`)
test_bot_formulae_args.push(`--deleted-formulae="${process.env.DELETED_FORMULAE}"`)
const test_bot_dependents_args = ["--only-formulae-dependents", "--junit"]
test_bot_dependents_args.push(`--testing-formulae="${process.env.TESTING_FORMULAE}"`)
if (label_names.includes('CI-test-bot-fail-fast')) {
console.log('CI-test-bot-fail-fast label found. Passing --fail-fast to brew test-bot.')
test_bot_formulae_args.push('--fail-fast')
test_bot_dependents_args.push('--fail-fast')
} else {
console.log('No CI-test-bot-fail-fast label found. Not passing --fail-fast to brew test-bot.')
}
if (label_names.includes('CI-build-dependents-from-source')) {
console.log('CI-build-dependents-from-source label found. Passing --build-dependents-from-source to brew test-bot.')
test_bot_dependents_args.push('--build-dependents-from-source')
} else {
console.log('No CI-build-dependents-from-source label found. Not passing --build-dependents-from-source to brew test-bot.')
}
if (label_names.includes('CI-skip-recursive-dependents')) {
console.log('CI-skip-recursive-dependents label found. Passing --skip-recursive-dependents to brew test-bot.')
test_bot_dependents_args.push('--skip-recursive-dependents')
} else {
console.log('No CI-skip-recursive-dependents label found. Not passing --skip-recursive-dependents to brew test-bot.')
}
if (label_names.includes('CI-skip-livecheck')) {
console.log('CI-skip-livecheck label found. Passing --skip-livecheck to brew test-bot.')
test_bot_formulae_args.push('--skip-livecheck')
} else {
console.log('No CI-skip-livecheck label found. Not passing --skip-livecheck to brew test-bot.')
}
core.setOutput('test-bot-formulae-args', test_bot_formulae_args.join(" "))
core.setOutput('test-bot-dependents-args', test_bot_dependents_args.join(" "))
setup_runners:
needs: [formulae_detect, setup_tests]
if: >
github.event_name == 'pull_request' &&
fromJson(needs.setup_tests.outputs.syntax-only) == false
runs-on: ubuntu-22.04
container:
image: ghcr.io/homebrew/ubuntu22.04:master
outputs:
runners: ${{steps.determine-runners.outputs.runners}}
runners_present: ${{steps.determine-runners.outputs.runners_present}}
env:
HOMEBREW_LINUX_RUNNER: ${{needs.setup_tests.outputs.linux-runner}}
HOMEBREW_LINUX_CLEANUP: ${{needs.setup_tests.outputs.cleanup-linux-runner}}
TESTING_FORMULAE: ${{needs.formulae_detect.outputs.testing_formulae}}
DELETED_FORMULAE: ${{needs.formulae_detect.outputs.deleted_formulae}}
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Determine runners to use for tests job
id: determine-runners
run: brew determine-test-runners "$TESTING_FORMULAE" "$DELETED_FORMULAE"
tests:
needs: [tap_syntax, setup_tests, setup_runners]
if: >
github.event_name == 'pull_request' &&
fromJson(needs.setup_tests.outputs.syntax-only) == false &&
fromJson(needs.setup_runners.outputs.runners_present)
strategy:
matrix:
include: ${{fromJson(needs.setup_runners.outputs.runners)}}
fail-fast: ${{fromJson(needs.setup_tests.outputs.fail-fast)}}
name: ${{matrix.name}}
runs-on: ${{matrix.runner}}
container: ${{matrix.container}}
timeout-minutes: ${{ matrix.timeout || fromJson(needs.setup_tests.outputs.timeout-minutes) }}
defaults:
run:
shell: /bin/bash -e {0}
working-directory: ${{matrix.workdir || github.workspace}}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.GITHUB_TOKEN}}
steps:
- name: Set environment variables
if: runner.os == 'macOS'
run: |
echo 'PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin' >> "$GITHUB_ENV"
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Enable debug mode
run: |
echo 'HOMEBREW_DEBUG=1' >> "${GITHUB_ENV}"
echo 'HOMEBREW_VERBOSE=1' >> "${GITHUB_ENV}"
if: runner.debug
- run: brew test-bot --only-cleanup-before
if: matrix.cleanup
- run: brew test-bot --only-setup
- name: Set up bottles directory
run: |
rm -rvf bottles
mkdir bottles
- run: brew test-bot ${{ needs.setup_tests.outputs.test-bot-formulae-args }}
id: brew-test-bot-formulae
working-directory: ${{matrix.workdir || github.workspace}}/bottles
- name: Failures summary for brew test-bot --only-formulae
if: always()
uses: Homebrew/actions/failures-summary-and-bottle-result@master
with:
workdir: ${{matrix.workdir || github.workspace}}
result_path: bottles/steps_output.txt
step_name: "Build summary on ${{ matrix.runner }}"
- name: Output brew linkage result
if: always()
uses: Homebrew/actions/failures-summary-and-bottle-result@master
with:
workdir: ${{matrix.workdir || github.workspace}}
result_path: bottles/linkage_output.txt
step_name: "`brew linkage` output on ${{ matrix.runner }}"
collapse: "true"
- name: Output brew bottle result
if: always()
uses: Homebrew/actions/failures-summary-and-bottle-result@master
with:
workdir: ${{matrix.workdir || github.workspace}}
result_path: bottles/bottle_output.txt
step_name: "`brew bottle` output on ${{ matrix.runner }}"
collapse: "true"
- name: Upload logs
if: always()
uses: actions/upload-artifact@main
with:
name: logs-${{ matrix.runner }}
path: ${{ runner.os == 'Linux' && needs.setup_tests.outputs.logs-dir || format('{0}/bottles/logs', matrix.workdir || github.workspace) }}
- name: Delete logs and home
if: always()
run: |
rm -rvf bottles/logs
rm -rvf bottles/home
- name: Count bottles
id: bottles
if: always()
working-directory: ${{matrix.workdir || github.workspace}}/bottles
run: |
shopt -s nullglob
json_files=(*.json)
count="${#json_files[@]}"
echo "$count bottles"
echo "count=$count" >> "$GITHUB_OUTPUT"
failed_json_files=(failed/*.json)
failures="${#failed_json_files[@]}"
echo "$failures failed bottles"
echo "failures=$failures" >> "$GITHUB_OUTPUT"
skipped_lists=(skipped_or_failed_formulae-*.txt)
skipped="${#skipped_lists[@]}"
echo "$skipped lists of skipped formulae"
echo "skipped=$skipped" >> "$GITHUB_OUTPUT"
- name: Upload failed bottles
if: always() && steps.bottles.outputs.failures > 0
uses: actions/upload-artifact@main
with:
name: bottles-${{ matrix.runner }}
path: ${{matrix.workdir || github.workspace}}/bottles/failed
# Must be run before the `Upload bottles` step so that failed
# bottles are not included in the `bottles` artifact.
- name: Delete failed bottles
if: always()
run: rm -rvf bottles/failed
- name: Upload bottles
if: always() && (steps.bottles.outputs.count > 0 || steps.bottles.outputs.skipped > 0)
uses: actions/upload-artifact@main
with:
name: bottles
path: ${{matrix.workdir || github.workspace}}/bottles
- name: Post cleanup
if: always() && matrix.cleanup
run: |
brew test-bot --only-cleanup-after
rm -rvf bottles
setup_dep_runners:
needs: [formulae_detect, setup_tests]
if: >
github.event_name == 'pull_request' &&
fromJson(needs.setup_tests.outputs.syntax-only) == false &&
fromJson(needs.setup_tests.outputs.test-dependents)
runs-on: ubuntu-22.04
container:
image: ghcr.io/homebrew/ubuntu22.04:master
outputs:
runners: ${{steps.determine-dependent-runners.outputs.runners}}
runners_present: ${{steps.determine-dependent-runners.outputs.runners_present}}
env:
HOMEBREW_LINUX_RUNNER: ${{needs.setup_tests.outputs.linux-runner}}
HOMEBREW_LINUX_CLEANUP: ${{needs.setup_tests.outputs.cleanup-linux-runner}}
TESTING_FORMULAE: ${{needs.formulae_detect.outputs.testing_formulae}}
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Determine runners to use for test_deps job
id: determine-dependent-runners
run: brew determine-test-runners --dependents --eval-all "$TESTING_FORMULAE"
conclusion:
needs: [tests, setup_tests, setup_runners]
if: always() && github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Check `tests` result
run: |
result='${{ needs.tests.result }}'
# Silence lint error about backtick usage inside single quotes.
# shellcheck disable=SC2016
printf '::notice ::`tests` job status: %s\n' "$result"
# Possible values are `success`, `failure`, `cancelled` or `skipped`.
# https://docs.github.com/en/actions/learn-github-actions/contexts#needs-context
if [[ "$result" = "failure" ]] || [[ "$result" = "cancelled" ]]
then
# Silence lint error about backtick usage inside single quotes.
# shellcheck disable=SC2016
printf '::error ::`tests` job %s.\n' "$result"
exit 1
fi
runners_present='${{ needs.setup_runners.outputs.runners_present }}'
syntax_only='${{ needs.setup_tests.outputs.syntax-only }}'
# The tests job can be skipped only if the PR is syntax-only
# or no runners were assigned.
if [[ "$result" = "skipped" ]] &&
[[ "$runners_present" = "false" || "$syntax_only" = "true" ]]
then
exit 0
fi
# The test job can succeed only if the PR is not syntax-only
# and runners were assigned. Otherwise it must have been skipped.
if [[ "$result" = "success" ]] &&
[[ "$runners_present" = "true" ]] &&
[[ "$syntax_only" = "false" ]]
then
exit 0
fi
# If we made it here, something went wrong with our workflow run that needs investigating.
printf '::error ::Unexpected outcome!\n'
# Silence lint error about backtick usage inside single quotes.
# shellcheck disable=SC2016
printf '::error ::`tests` job result: %s\n' "$result" # success/skipped
printf '::error ::runners assigned: %s\n' "$runners_present" # true/false
printf '::error ::syntax-only: %s\n' "$syntax_only" # true/false
exit 1
test_deps:
needs: [tap_syntax, setup_tests, setup_dep_runners, tests]
if: >
(success() ||
(failure() && contains(github.event.pull_request.labels.*.name, 'CI-no-fail-fast'))) &&
github.event_name == 'pull_request' &&
fromJson(needs.setup_tests.outputs.syntax-only) == false &&
fromJson(needs.setup_tests.outputs.test-dependents) &&
fromJson(needs.setup_dep_runners.outputs.runners_present)
strategy:
matrix:
include: ${{fromJson(needs.setup_dep_runners.outputs.runners)}}
fail-fast: ${{fromJson(needs.setup_tests.outputs.fail-fast)}}
name: ${{matrix.name}} (deps)
runs-on: ${{matrix.runner}}
container: ${{matrix.container}}
timeout-minutes: ${{ matrix.timeout || fromJson(needs.setup_tests.outputs.timeout-minutes) }}
defaults:
run:
shell: /bin/bash -e {0}
working-directory: ${{matrix.workdir || github.workspace}}
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
HOMEBREW_GITHUB_API_TOKEN: ${{secrets.GITHUB_TOKEN}}
steps:
- name: Set environment variables
if: runner.os == 'macOS'
run: |
echo 'PATH=/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin' >> "$GITHUB_ENV"
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Enable debug mode
run: |
echo 'HOMEBREW_DEBUG=1' >> "${GITHUB_ENV}"
echo 'HOMEBREW_VERBOSE=1' >> "${GITHUB_ENV}"
if: runner.debug
- run: brew test-bot --only-cleanup-before
if: matrix.cleanup
- name: Download bottles from GitHub Actions
uses: actions/download-artifact@v3
with:
name: bottles
path: ${{matrix.workdir || github.workspace}}/bottles
- run: brew test-bot ${{ needs.setup_tests.outputs.test-bot-dependents-args }}
working-directory: ${{matrix.workdir || github.workspace}}/bottles
- name: Failures summary for brew test-bot ${{ needs.setup_tests.outputs.test-bot-dependents-args }}
if: always()
uses: Homebrew/actions/failures-summary-and-bottle-result@master
with:
workdir: ${{matrix.workdir || github.workspace}}
result_path: bottles/steps_output.txt
step_name: "Dependent summary on ${{ matrix.runner }}"
collapse: "true"
- name: Upload logs
if: always()
uses: actions/upload-artifact@main
with:
name: logs-deps-${{ matrix.runner }}
path: ${{matrix.workdir || github.workspace}}/bottles/logs
- name: Delete logs and home
if: always()
run: |
rm -rvf bottles/logs
rm -rvf bottles/home
- name: Post cleanup
if: always() && matrix.cleanup
run: |
brew test-bot --only-cleanup-after
rm -rvf bottles