-
Notifications
You must be signed in to change notification settings - Fork 4
185 lines (174 loc) · 6.1 KB
/
integration.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
name: Integration tests
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
types:
- opened
- reopened
- synchronize
- converted_to_draft
- ready_for_review
- labeled
- unlabeled
- auto_merge_enabled
- auto_merge_disabled
merge_group:
permissions:
actions: read
checks: write
contents: read
statuses: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
pre_check:
uses: ./.github/workflows/pre-check-integration.yml
matrix-test:
needs: pre_check
if: needs.pre_check.outputs.should_run == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
variation: [one, two]
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- name: Recreate integration-test-result if needed
id: get-pending-integration-result
uses: ./.github/actions/get-latest-check
with:
create-if-needed: true
- name: Get the behavior from the PR description
id: get-behavior
uses: actions/github-script@v6
with:
result-encoding: string
script: |
let behavior = {};
if (context.payload.pull_request) {
const { body } = context.payload.pull_request;
core.debug(`body: ${body}`)
const regex = /^\#matrix-test-${{ matrix.variation }}:\s+(.*)$/m;
const result = regex.exec(body);
core.debug(`regex result: ${result}`)
if (result) {
behavior = JSON.parse(result[1]);
}
const attempt = behavior.attempts && behavior.attempts[${{ github.run_attempt }} - 1] || {}
behavior = {...behavior, ...attempt}
}
console.log(behavior);
return JSON.stringify(behavior);
- name: run matrix test
run: |
sleep ${{ fromJSON(steps.get-behavior.outputs.result).sleep || 60 }}
exit ${{ fromJSON(steps.get-behavior.outputs.result).exitCode || 0 }}
continue-on-error: ${{ matrix.variation == 'two' }}
standalone-test:
needs: pre_check
if: >-
needs.pre_check.outputs.should_run == 'true' &&
(
github.event_name != 'pull_request' ||
!contains(github.event.pull_request.labels.*.name, 'skip:standalone')
)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- name: Recreate integration-test-result if needed
id: get-pending-integration-result
uses: ./.github/actions/get-latest-check
with:
create-if-needed: true
- name: Get the behavior from the PR description
id: get-behavior
uses: actions/github-script@v6
with:
result-encoding: string
script: |
let behavior = {};
if (context.payload.pull_request) {
const { body } = context.payload.pull_request;
core.debug(`body: ${body}`)
const regex = /^\#standalone-test:\s+(.*)$/m;
const result = regex.exec(body);
core.debug(`regex result: ${result}`)
if (result) {
behavior = JSON.parse(result[1]);
}
const attempt = behavior.attempts && behavior.attempts[${{ github.run_attempt }} - 1] || {}
behavior = {...behavior, ...attempt}
}
console.log(behavior);
return JSON.stringify(behavior);
- name: run standalone test
run: |
sleep ${{ fromJSON(steps.get-behavior.outputs.result).sleep || 45 }}
exit ${{ fromJSON(steps.get-behavior.outputs.result).exitCode || 0 }}
set-integration-result-in-progress:
needs: pre_check
if: needs.pre_check.outputs.should_run == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: get-pending-integration-result
uses: ./.github/actions/get-latest-check
with:
create-if-needed: true
- name: Update integration-test-result check to in-progress
uses: actions/github-script@v6
with:
script: |
const runId = "${{ steps.get-pending-integration-result.outputs.run_id }}";
const res = await github.rest.checks.update({
...context.repo,
check_run_id: runId,
status: "in_progress",
})
core.debug(`Check update response: ${JSON.stringify(res, null, 2)}`)
console.log(`Updated check ${runId} to in-progress`)
finalize-integration-result:
needs:
- pre_check
- matrix-test
- standalone-test
if: >-
always() &&
needs.pre_check.result == 'success' &&
needs.matrix-test.result != 'cancelled' &&
needs.standalone-test.result != 'cancelled' &&
(
needs.pre_check.outputs.should_run == 'true' ||
needs.pre_check.outputs.previous_success == 'true'
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: get-pending-integration-result
uses: ./.github/actions/get-latest-check
with:
create-if-needed: true
- name: Publish integration-test-result
if: always()
uses: actions/github-script@v6
with:
script: |
const runId = "${{ steps.get-pending-integration-result.outputs.run_id }}";
const previousSuccess = ${{ needs.pre_check.outputs.previous_success }};
const matrixTestSuccess = "${{ needs.matrix-test.result }}" === "success";
const standaloneTestSuccess = "${{ needs.standalone-test.result }}" === "success";
const conclusion = previousSuccess || (matrixTestSuccess && standaloneTestSuccess) ?
'success' : 'failure';
const res = await github.rest.checks.update({
...context.repo,
check_run_id: runId,
conclusion,
})
core.debug(`Check update response: ${JSON.stringify(res, null, 2)}`)
console.log(`Updated check ${runId} to ${conclusion}`)