-
Notifications
You must be signed in to change notification settings - Fork 965
225 lines (204 loc) · 7.36 KB
/
Copy pathe2e-pr-trigger.yml
File metadata and controls
225 lines (204 loc) · 7.36 KB
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
name: E2E PR Trigger
# Automatically adds the E2E/Run label to non-draft PRs targeting master.
# Adding the label signals Matterwick to provision cloud servers and dispatch
# the Electron Playwright Tests (e2e-functional.yml) workflow.
# After tests complete, e2e-functional.yml / e2e-label-cleanup.yml remove the label.
#
# E2E/Override (same contract as mattermost-mobile): when present on a PR,
# opened/synchronize events do not add E2E/Run, and applying the override label
# strips E2E/Run and cancels in-flight E2E runs.
#
# On synchronize: in-progress Electron Playwright Tests runs for this PR are
# cancelled before re-adding the label so stale runs for the old commit do not
# block the new one. Runs on other PR branches are left running.
#
# The concurrency group ensures rapid pushes to the same PR don't queue multiple
# label operations: only the most recent push proceeds.
on:
pull_request:
types:
- opened
- reopened
- ready_for_review
- synchronize
- labeled
- unlabeled
branches:
- master
concurrency:
group: e2e-pr-trigger-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
add-e2e-label:
name: Add E2E/Run label
runs-on: ubuntu-22.04
permissions:
issues: write
pull-requests: write
actions: write
statuses: write
if: >-
!github.event.pull_request.draft
&& contains(fromJSON('["opened", "reopened", "ready_for_review", "synchronize"]'), github.event.action)
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.pull_request.base.ref }}
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
if: github.event.pull_request.head.repo.full_name == github.repository
with:
ref: ${{ github.event.pull_request.head.sha }}
sparse-checkout: |
e2e/utils/github-actions.js
sparse-checkout-cone-mode: false
- name: Cancel running E2E tests and re-trigger
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ github.token }}
script: |
const {cancelActiveE2ERuns, markE2EStatusesCancelled} = require('./e2e/utils/github-actions.js');
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const pr = context.payload.pull_request;
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner,
repo,
issue_number,
});
const labelNames = labels.map((label) => label.name);
if (labelNames.includes('E2E/Override')) {
core.info(`PR #${issue_number} has E2E/Override — skipping E2E/Run refresh.`);
if (labelNames.includes('E2E/Run')) {
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number,
name: 'E2E/Run',
});
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
}
await cancelActiveE2ERuns({
github,
context,
prNumber: issue_number,
headBranch: pr.head.ref,
});
await markE2EStatusesCancelled({
github,
context,
sha: pr.head.sha,
reason: 'E2E skipped (E2E/Override label active)',
});
return;
}
await cancelActiveE2ERuns({
github,
context,
prNumber: issue_number,
headBranch: pr.head.ref,
});
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number,
name: 'E2E/Run',
});
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
await github.rest.issues.addLabels({
owner,
repo,
issue_number,
labels: ['E2E/Run'],
});
honor-e2e-override:
name: Honor E2E/Override
runs-on: ubuntu-22.04
permissions:
issues: write
pull-requests: write
actions: write
statuses: write
if: >-
github.event.action == 'labeled'
&& github.event.label.name == 'E2E/Override'
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.pull_request.base.ref }}
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
if: github.event.pull_request.head.repo.full_name == github.repository
with:
ref: ${{ github.event.pull_request.head.sha }}
sparse-checkout: |
e2e/utils/github-actions.js
sparse-checkout-cone-mode: false
- name: Strip E2E/Run and cancel in-flight E2E
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ github.token }}
script: |
const {cancelActiveE2ERuns, markE2EStatusesCancelled} = require('./e2e/utils/github-actions.js');
const { owner, repo } = context.repo;
const issue_number = context.issue.number;
const pr = context.payload.pull_request;
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number,
name: 'E2E/Run',
});
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
await cancelActiveE2ERuns({
github,
context,
prNumber: issue_number,
headBranch: pr.head.ref,
});
await markE2EStatusesCancelled({
github,
context,
sha: pr.head.sha,
reason: 'E2E cancelled (E2E/Override label applied)',
});
cancel-on-manual-unlabel:
name: Cancel E2E on manual label removal
runs-on: ubuntu-22.04
permissions:
actions: write
statuses: write
pull-requests: read
if: >-
github.event.action == 'unlabeled'
&& github.event.label.name == 'E2E/Run'
&& github.event.sender.login != 'github-actions[bot]'
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
ref: ${{ github.event.pull_request.base.ref }}
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
if: github.event.pull_request.head.repo.full_name == github.repository
with:
ref: ${{ github.event.pull_request.head.sha }}
sparse-checkout: |
e2e/utils/github-actions.js
sparse-checkout-cone-mode: false
- name: Cancel E2E runs and mark statuses skipped
uses: ./.github/actions/cancel-e2e-runs
with:
pr_number: ${{ github.event.pull_request.number }}
reason: E2E cancelled (E2E/Run label removed)