195 lines (175 loc) · 6.97 KB
/
try_labels.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
name: Try (Label)
on:
pull_request_target:
types: [labeled]
jobs:
parse-comment:
name: Trigger Try
runs-on: ubuntu-latest
concurrency:
group: try-${{ github.event.number }}
outputs:
configuration: ${{ steps.configuration.outputs.config }}
try_string: ${{ steps.try_string.outputs.result }}
steps:
- name: Collect Labels
uses: actions/github-script@v6
id: try_string
with:
result-encoding: string
script: |
function makeComment(body) {
console.log(body);
if (context.eventName != 'pull_request_target')
return;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
}
let try_string = "${{ inputs.try_string }}" || "";
if (context.eventName == 'pull_request_target') {
for (const label of context.payload.pull_request.labels) {
if (!label.name.startsWith("T-")) {
continue;
}
// Try to remove the label. If that fails, it's likely that another
// workflow has already processed it or a user has removed it.
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: label.name,
});
} catch (exception) {
console.log("Assuming '" + label.name + "' is already removed: " + exception);
continue;
}
console.log("Found label: " + label.name);
// Remove the "T-" prefix.
label = label.name.slice(2);
try_string += " " + label;
}
}
console.log(try_string);
// Exit early if the try string is empty (no try triggered).
if (!try_string.trim()) {
return "";
}
let username = context.payload.sender.login;
let result = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username
});
if (!result.data.user.permissions.push) {
makeComment('🔒 User @' + username + ' does not have permission to trigger try jobs.');
return "";
}
return try_string;
- uses: actions/checkout@v3
if: github.event_name != 'pull_request_target'
with:
fetch-depth: 1
sparse-checkout: |
python/try_parser.py
sparse-checkout-cone-mode: false
# This is necessary to checkout the pull request if this run was triggered
# via an `issue_comment` action on a pull request.
- uses: actions/checkout@v3
if: github.event_name == 'pull_request_target'
with:
ref: refs/pull/${{ github.event.number }}/head
fetch-depth: 1
sparse-checkout: |
python/try_parser.py
sparse-checkout-cone-mode: false
- name: Parse Try string
if: ${{ steps.try_string.outputs.result }}
id: configuration
run: |
out=$(python ./python/try_parser.py ${{ steps.try_string.outputs.result }})
echo "config<<EOF"$'\n'"$out"$'\n'EOF >> $GITHUB_OUTPUT
- name: Collect Labels
if: ${{ steps.try_string.outputs.result }}
uses: actions/github-script@v6
with:
result-encoding: string
script: |
let config = ${{ steps.configuration.outputs.config }};
function makeComment(body) {
console.log(body);
if (context.eventName != 'pull_request_target')
return;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
}
const url = context.serverUrl +
"/" + context.repo.owner +
"/" + context.repo.repo +
"/actions/runs/" + context.runId;
const formattedURL = "[#" + context.runId + "](" + url + ")";
makeComment("🔨 Triggering try run (" + formattedURL + ") for "
+ config.matrix.map(m => m.name).join(", "));
run-try:
if: ${{ needs.parse-comment.outputs.try_string }}
needs: ["parse-comment"]
name: ${{ matrix.name }}
strategy:
fail-fast: ${{ fromJson(needs.parse-comment.outputs.configuration).fail_fast }}
matrix:
include: ${{ fromJson(needs.parse-comment.outputs.configuration).matrix }}
# We need to use `dipatch-workflow.yml` because workflows do not support using: ${}.
uses: ./.github/workflows/dispatch-workflow.yml
secrets: inherit
with:
workflow: ${{ matrix.workflow }}
wpt-layout: ${{ matrix.wpt_layout }}
profile: ${{ matrix.profile }}
unit-tests: ${{ matrix.unit_tests }}
wpt-tests-to-run: ${{ matrix.wpt_tests_to_run }}
results:
name: Results
needs: ["parse-comment", "run-try"]
runs-on: ubuntu-latest
if: ${{ always() && needs.parse-comment.outputs.try_string }}
steps:
- name: Success
if: ${{ github.event_name == 'pull_request_target' && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
uses: actions/github-script@v6
with:
script: |
const url = context.serverUrl +
"/" + context.repo.owner +
"/" + context.repo.repo +
"/actions/runs/" + context.runId;
const formattedURL = "[#" + context.runId + "](" + url + ")";
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "✨ Try run (" + formattedURL + ") " + "succeeded.",
});
- name: Failure
if: ${{ github.event_name == 'pull_request_target' && contains(needs.*.result, 'failure') }}
uses: actions/github-script@v6
with:
script: |
const url = context.serverUrl +
"/" + context.repo.owner +
"/" + context.repo.repo +
"/actions/runs/" + context.runId;
const formattedURL = "[#" + context.runId + "](" + url + ")";
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "⚠️ Try run (" + formattedURL + ") " + "failed.",
});