4
4
schedule :
5
5
- cron : " 0 9 * * *" # 9am UTC = 1am PST / 2am PDT
6
6
7
+ pull_request :
8
+ types : [ labeled, closed ]
9
+
7
10
workflow_dispatch :
8
11
inputs :
9
12
build_os :
41
44
description : ' Optional: Pull request # to build and test? (With optional commit hash, separated by a colon. Specify the FULL hash.)'
42
45
43
46
env :
47
+ triggerLabelPrefix : " tests-requested: "
48
+ triggerLabelFull : " tests-requested: full"
49
+ triggerLabelQuick : " tests-requested: quick"
44
50
pythonVersion : ' 3.7'
45
51
artifactRetentionDays : 2
46
52
@@ -69,32 +75,69 @@ jobs:
69
75
env :
70
76
GITHUB_TOKEN : ${{ github.token }}
71
77
# ## It sets "github_ref,trigger,pr_number,requested_tests" outputs to control the following jobs and steps
72
- # ## trigger value: manual_trigger, scheduled_trigger;
73
- # ## TODO: label_trigger, postsubmit_trigger, presubmit_trigger
78
+ # ## trigger value: manual_trigger, scheduled_trigger, label_trigger, postsubmit_trigger
74
79
- id : set_outputs
75
80
run : |
76
81
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
77
- echo "::set-output name=trigger::manual_trigger"
78
- if [[ "${{ github.event.inputs.use_expanded_matrix }}" == "1" ]]; then
79
- echo "::set-output name=requested_tests::expanded"
80
- fi
81
- if [[ -z "${{github.event.inputs.test_pull_request}}" ]]; then
82
- # test_pull_request not specified
82
+ if [[ "${{ github.event.inputs.test_pull_request }}" != "nightly-packaging" ]]; then
83
+ # Triggered manually
84
+ echo "::set-output name=trigger::manual_trigger"
85
+ if [[ "${{ github.event.inputs.use_expanded_matrix }}" == "1" ]]; then
86
+ echo "::set-output name=requested_tests::expanded"
87
+ fi
88
+ if [[ -z "${{github.event.inputs.test_pull_request}}" ]]; then
89
+ # test_pull_request not specified
90
+ echo "::set-output name=github_ref::$GITHUB_SHA"
91
+ elif [[ "${{github.event.inputs.test_pull_request}}" == *:* ]]; then
92
+ # If specified as pr:commit_hash, split them.
93
+ echo "::set-output name=github_ref::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f2)"
94
+ echo "::set-output name=pr_number::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f1)"
95
+ else
96
+ # Just the PR specified, use refs/pull/<number>/merge as the ref.
97
+ echo "::set-output name=github_ref::refs/pull/${{github.event.inputs.test_pull_request}}/merge"
98
+ echo "::set-output name=pr_number::${{ github.event.inputs.test_pull_request }}"
99
+ fi
100
+ elif [[ "${{ github.event.inputs.test_pull_request }}" == "nightly-packaging" ]]; then
101
+ # Triggered by scheduled packaging SDK workflow.
102
+ echo "::set-output name=trigger::scheduled_trigger"
83
103
echo "::set-output name=github_ref::$GITHUB_SHA"
84
- elif [[ "${{github.event.inputs.test_pull_request}}" == *:* ]]; then
85
- # If specified as pr:commit_hash, split them.
86
- echo "::set-output name=github_ref::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f2)"
87
- echo "::set-output name=pr_number::$(echo ${{ github.event.inputs.test_pull_request }} | cut -d: -f1)"
88
- else
89
- # Just the PR specified, use refs/pull/<number>/merge as the ref.
90
- echo "::set-output name=github_ref::refs/pull/${{github.event.inputs.test_pull_request}}/merge"
91
- echo "::set-output name=pr_number::${{ github.event.inputs.test_pull_request }}"
104
+ echo "::set-output name=requested_tests::expanded"
92
105
fi
93
106
elif [[ "${{ github.event_name }}" == "schedule" ]]; then
94
107
echo "::set-output name=trigger::scheduled_trigger"
95
108
echo "::set-output name=github_ref::$GITHUB_SHA"
96
109
echo "::set-output name=requested_tests::expanded"
110
+ elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
111
+ echo "::set-output name=github_ref::$GITHUB_SHA"
112
+ if [[ "${{ github.event.action }}" == "labeled" && "${{ github.event.label.name }}" == "${{ env.triggerLabelPrefix }}"* ]]; then
113
+ echo "::set-output name=trigger::label_trigger"
114
+ echo "::set-output name=pr_number::${{ github.event.pull_request.number }}"
115
+ if [[ "${{ github.event.label.name }}" == "${{ env.triggerLabelQuick }}" ]]; then
116
+ echo "::set-output name=requested_tests::auto"
117
+ else
118
+ echo "::set-output name=requested_tests::expanded"
119
+ fi
120
+ elif [[ "${{ github.event.action }}" == "closed" && ${{ github.event.pull_request.merged == true }} ]]; then
121
+ echo "::set-output name=trigger::postsubmit_trigger"
122
+ echo "::set-output name=pr_number::${{ github.event.pull_request.number }}"
123
+ echo "::set-output name=requested_tests::auto"
124
+ fi
97
125
fi
126
+ # ## If it's not a defined trigger, cancel workflow
127
+ # ## e.g. Triggered by non-"test-request" label; triggered by not merged PR close event.
128
+ - name : Cancel workflow
129
+ if : ${{ !steps.set_outputs.outputs.trigger }}
130
+
131
+ - name : Wait for workflow cancellation
132
+ if : ${{ !steps.set_outputs.outputs.trigger }}
133
+ run : |
134
+ sleep 300
135
+ exit 1 # fail out if the cancellation above somehow failed.
136
+ - name : Cancel previous runs on the same PR
137
+ if : steps.set_outputs.outputs.trigger == 'label_trigger'
138
+
139
+ with :
140
+ access_token : ${{ github.token }}
98
141
- uses : actions/checkout@v2
99
142
with :
100
143
ref : ${{steps.set_outputs.outputs.github_ref}}
@@ -111,6 +154,19 @@ jobs:
111
154
if [[ "${{ steps.set_outputs.outputs.requested_tests }}" == "expanded" ]]; then
112
155
TEST_MATRIX_PARAM=-e=1
113
156
echo "::warning ::Running on the expanded matrix"
157
+ elif [[ "${{ steps.set_outputs.outputs.requested_tests }}" == "minimal" ]]; then
158
+ TEST_MATRIX_PARAM=-m=1
159
+ echo "::warning ::Running on the minimal matrix"
160
+ elif [[ "${{ steps.set_outputs.outputs.requested_tests }}" == "auto" ]]; then
161
+ # auto-diff only apply when running in a PR.
162
+ # diff against the PR's base. "git merge-base main branch_name" will give the common ancestor of both branches.
163
+ MERGE_BASE=$(git merge-base origin/${{github.event.pull_request.head.ref}} origin/${{github.event.pull_request.base.ref}} || true)
164
+ # If origin/<branch> is no longer valid, then just run all tests.
165
+ if [[ -n "${MERGE_BASE}" ]]; then
166
+ echo "::warning ::Auto-diff origin/${{github.event.pull_request.head.ref}}..${MERGE_BASE}"
167
+ git diff --name-only origin/${{github.event.pull_request.head.ref}}..${MERGE_BASE}
168
+ TEST_MATRIX_PARAM="--auto_diff origin/${{github.event.pull_request.head.ref}}..${MERGE_BASE}"
169
+ fi
114
170
fi
115
171
116
172
# To feed input into the job matrix, we first need to convert to a JSON
@@ -228,6 +284,21 @@ jobs:
228
284
--version ${{ matrix.unity_version }} \
229
285
--logfile "testapps/release_license.log"
230
286
cat testapps/release_license.log
287
+ - name : Prepare results summary artifact
288
+ if : ${{ !cancelled() }}
289
+ shell : bash
290
+ run : |
291
+ if [ ! -f build-results-${{matrix.os}}-${{ matrix.unity_version }}-all.log.json ]; then
292
+ # No summary was created, make a placeholder one.
293
+ echo "__SUMMARY_MISSING__" > build-results-${{matrix.os}}-${{ matrix.unity_version }}-all.log.json
294
+ fi
295
+ - name : Upload build results artifact
296
+
297
+ if : ${{ !cancelled() }}
298
+ with :
299
+ name : log-artifact
300
+ path : build-results-${{matrix.os}}-${{ matrix.unity_version }}-all*
301
+ retention-days : ${{ env.artifactRetentionDays }}
231
302
- name : Upload Android integration tests artifact
232
303
233
304
if : contains(needs.check_and_prepare.outputs.platform, 'Android') && ${{ !cancelled() }}
@@ -263,6 +334,21 @@ jobs:
263
334
name : testapps-${{matrix.os}}-${{ matrix.unity_version }}-windows-latest
264
335
path : testapps-${{matrix.os}}-${{ matrix.unity_version }}-all/Windows
265
336
retention-days : ${{ env.artifactRetentionDays }}
337
+ - name : Download log artifacts
338
+ if : ${{ needs.check_and_prepare.outputs.pr_number && failure() && !cancelled() }}
339
+
340
+ with :
341
+ path : test_results
342
+ name : log-artifact
343
+ - name : Update PR label and comment
344
+ if : ${{ needs.check_and_prepare.outputs.pr_number && failure() && !cancelled() }}
345
+ run : |
346
+ python scripts/gha/it_workflow.py --stage progress \
347
+ --token ${{github.token}} \
348
+ --issue_number ${{needs.check_and_prepare.outputs.pr_number}}\
349
+ --actor ${{github.actor}} \
350
+ --commit ${{needs.check_and_prepare.outputs.github_ref}} \
351
+ --run_id ${{github.run_id}}
266
352
- name : Summarize build results
267
353
if : ${{ !cancelled() }}
268
354
shell : bash
@@ -308,6 +394,37 @@ jobs:
308
394
run : |
309
395
python scripts/gha/desktop_tester.py --testapp_dir testapps \
310
396
--logfile_name "${{ matrix.build_os }}-${{ matrix.unity_version }}-${{ matrix.os }}-desktop"
397
+ - name : Prepare results summary artifact
398
+ if : ${{ !cancelled() }}
399
+ shell : bash
400
+ run : |
401
+ if [ ! -f testapps/test-results-${{ matrix.build_os }}-${{ matrix.unity_version }}-${{ matrix.os }}-desktop.log.json ]; then
402
+ mkdir -p testapps && echo "__SUMMARY_MISSING__" > testapps/test-results-${{ matrix.build_os }}-${{ matrix.unity_version }}-${{ matrix.os }}-desktop.log.json
403
+ fi
404
+ - name : Upload Desktop test results artifact
405
+ if : ${{ !cancelled() }}
406
+
407
+ with :
408
+ name : log-artifact
409
+ path : testapps/test-results-${{ matrix.build_os }}-${{ matrix.unity_version }}-${{ matrix.os }}-desktop*
410
+ retention-days : ${{ env.artifactRetentionDays }}
411
+ - name : Download log artifacts
412
+ if : ${{ needs.check_and_prepare.outputs.pr_number && failure() && !cancelled() }}
413
+
414
+ with :
415
+ path : test_results
416
+ name : log-artifact
417
+ - name : Update PR label and comment
418
+ shell : bash
419
+ if : ${{ needs.check_and_prepare.outputs.pr_number && failure() && !cancelled() }}
420
+ run : |
421
+ pushd ${{env.GCS_UPLOAD_DIR}}
422
+ python scripts/gha/it_workflow.py --stage progress \
423
+ --token ${{github.token}} \
424
+ --issue_number ${{needs.check_and_prepare.outputs.pr_number}}\
425
+ --actor ${{github.actor}} \
426
+ --commit ${{needs.check_and_prepare.outputs.github_ref}} \
427
+ --run_id ${{github.run_id}}
311
428
- name : Summarize test results
312
429
if : ${{ !cancelled() }}
313
430
shell : bash
@@ -372,6 +489,35 @@ jobs:
372
489
python scripts/gha/test_simulator.py --testapp_dir testapps \
373
490
--logfile_name "${{ matrix.build_os }}-${{ matrix.unity_version }}-${{ matrix.platform }}" \
374
491
--ci
492
+ - name : Prepare results summary artifact
493
+ if : ${{ !cancelled() }}
494
+ shell : bash
495
+ run : |
496
+ if [ ! -f testapps/test-results-${{ matrix.build_os }}-${{ matrix.unity_version }}-${{ matrix.platform }}.log.json ]; then
497
+ mkdir -p testapps && echo "__SUMMARY_MISSING__" > testapps/test-results-${{ matrix.build_os }}-${{ matrix.unity_version }}-${{ matrix.platform }}.log.json
498
+ fi
499
+ - name : Upload Desktop test results artifact
500
+ if : ${{ !cancelled() }}
501
+
502
+ with :
503
+ name : log-artifact
504
+ path : testapps/test-results-${{ matrix.build_os }}-${{ matrix.unity_version }}-${{ matrix.platform }}*
505
+ retention-days : ${{ env.artifactRetentionDays }}
506
+ - name : Download log artifacts
507
+ if : ${{ needs.check_and_prepare.outputs.pr_number && failure() && !cancelled() }}
508
+
509
+ with :
510
+ path : test_results
511
+ name : log-artifact
512
+ - name : Update PR label and comment
513
+ if : ${{ needs.check_and_prepare.outputs.pr_number && failure() && !cancelled() }}
514
+ run : |
515
+ python scripts/gha/it_workflow.py --stage progress \
516
+ --token ${{github.token}} \
517
+ --issue_number ${{needs.check_and_prepare.outputs.pr_number}}\
518
+ --actor ${{github.actor}} \
519
+ --commit ${{needs.check_and_prepare.outputs.github_ref}} \
520
+ --run_id ${{github.run_id}}
375
521
- name : Summarize test results
376
522
if : ${{ !cancelled() }}
377
523
shell : bash
0 commit comments