Repository navigation
170 lines (156 loc) · 6.3 KB
/
Copy pathtry-label.yml
File metadata and controls
170 lines (156 loc) · 6.3 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
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@v8
id: try_string
with:
result-encoding: string
script: |
function makeComment(body) {
console.log(body);
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
}
let try_string = "";
for (let 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 "";
}
return try_string;
- uses: actions/checkout@v6
with:
sparse-checkout: |
python/servo/try_parser.py
.github/actions/setup-python
.python-version
uv.lock
sparse-checkout-cone-mode: false
- name: Setup Python
uses: ./.github/actions/setup-python
- name: Parse Labels
if: ${{ steps.try_string.outputs.result }}
id: configuration
run: |
{
echo 'config<<EOF'
python ./python/servo/try_parser.py ${{ steps.try_string.outputs.result }}
echo EOF
} >> $GITHUB_OUTPUT
- name: Comment Run Start
if: ${{ steps.try_string.outputs.result }}
uses: actions/github-script@v8
with:
result-encoding: string
script: |
let config = ${{ steps.configuration.outputs.config }};
function makeComment(body) {
console.log(body);
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 `dispatch-workflow.yml` because workflows do not support using: ${}.
uses: ./.github/workflows/dispatch-workflow.yml
secrets: inherit
with:
workflow: ${{ matrix.workflow }}
wpt: ${{ matrix.wpt }}
profile: ${{ matrix.profile }}
unit-tests: ${{ matrix.unit_tests }}
devtools-tests: ${{ matrix.devtools_tests }}
build-libservo: ${{ matrix.build_libservo }}
wpt-args: ${{ matrix.wpt_args }}
build-args: ${{ matrix.build_args }}
number-of-wpt-chunks: ${{ matrix.number_of_wpt_chunks }}
bencher: ${{ matrix.bencher }}
coverage: ${{ matrix.coverage }}
capi: ${{ matrix.capi }}
results:
name: Results
needs: ["parse-comment", "run-try"]
runs-on: ubuntu-latest
if: ${{ always() && needs.parse-comment.outputs.try_string }}
steps:
- name: Post PR Comment with results
env:
PR_NUMBER: ${{ github.event.number }}
ACTIONS_RUN_URL: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
GH_TOKEN: ${{ github.token }}
run: |
REQUIRED_MQ_JOBS_SUCCEEDED=${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
# Using `contains()` on the output object doesn't seem to work, so we convert to JSON and use
# jq at runtime to check the fields of the optional jobs.
OPTIONAL_JOB_STATUS_JSON="${{toJSON(needs.run-try.outputs.ohos_optional_job_status)}}"
OPTIONAL_JOBS_SUCCEEDED=$(echo "${OPTIONAL_JOB_STATUS_JSON}" | jq 'all(.[].result == "success"; .)')
# The variables expand to `true` or `false`, which can be directly run to evaluate the condition.
if ${REQUIRED_MQ_JOBS_SUCCEEDED} && ${OPTIONAL_JOBS_SUCCEEDED} ; then
RESULT_EMOJI="✨"
TRY_RESULT="succeeded."
elif ${REQUIRED_MQ_JOBS_SUCCEEDED} ; then
RESULT_EMOJI="⚠️"
TRY_RESULT="succeeded with failures of jobs that don't block the Merge Queue. Please check the workflow run for details."
elif ${{ contains(needs.*.result, 'failure') }} ; then
RESULT_EMOJI="⚠️"
TRY_RESULT="failed!"
else
RESULT_EMOJI="⚠️"
TRY_RESULT="cancelled."
fi
gh pr comment ${PR_NUMBER} --repo ${{ github.repository }} --body "${RESULT_EMOJI} Try run ([#${{ github.run_id }}](${ACTIONS_RUN_URL})) ${TRY_RESULT}"