Repository navigation
542 lines (481 loc) · 20.8 KB
/
Copy pathdispatch.yml
File metadata and controls
542 lines (481 loc) · 20.8 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
name: Dispatch
on:
# labels on PRs
pull_request_target:
types: [labeled]
# slash commands & trust commands
issue_comment:
types: [created, edited]
permissions:
actions: write
pull-requests: write
contents: read
# Unique marker correlating a dispatched run with this dispatcher invocation.
# The dispatch step and its matching find-run step MUST use the same value, so
# define it once here rather than repeating the expression at every call site.
env:
DISTINCT_ID: ${{ github.run_id }}-${{ github.run_attempt }}
jobs:
# ---------------------------------------------------------------------------
# LABEL: TRUSTED AUTHOR
# ---------------------------------------------------------------------------
label-trusted-author:
if: github.event_name == 'pull_request_target' &&
github.event.label.name == 'trusted-author'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Get PR author login
id: pr
uses: actions/github-script@v7
with:
script: |
const login = (context.payload.pull_request.user.login || '').toLowerCase();
if (!login) {
core.setFailed('Could not determine PR author login');
return;
}
core.setOutput('login', login);
- id: find
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: github-actions[bot]
body-includes: "[HIL trust list]"
- name: Upsert trust list for author
id: upsert
uses: actions/github-script@v7
with:
script: |
const { upsertTrusted } = require('./.github/scripts/hil-trust.js');
const existing = `${{ toJson(steps.find.outputs.comment-body || '') }}`;
const login = '${{ steps.pr.outputs.login }}'.toLowerCase();
const { body } = upsertTrusted(existing, login);
core.setOutput('body', body);
- uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find.outputs.comment-id }}
body: ${{ steps.upsert.outputs.body }}
edit-mode: replace
- uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Author **@${{ steps.pr.outputs.login }}** was trusted for this PR via the `trusted-author` label.
They can now use `/hil quick`, `/hil full` and `/hil <CHIPS>` and their features.
# ---------------------------------------------------------------------------
# TRUST MANAGEMENT (/trust, /revoke)
# ---------------------------------------------------------------------------
trust:
if: >
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
(github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'OWNER') &&
startsWith(github.event.comment.body, '/trust ')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Parse login
id: parse
uses: actions/github-script@v7
with:
script: |
const { parseTrustCommand } = require('./.github/scripts/hil-trust.js');
const res = parseTrustCommand(context.payload.comment.body, 'trust');
if (res.error) core.setFailed(res.error);
core.setOutput('login', res.login);
- id: find
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
comment-author: github-actions[bot]
body-includes: "[HIL trust list]"
- name: Upsert trust list
id: upsert
uses: actions/github-script@v7
with:
script: |
const { upsertTrusted } = require('./.github/scripts/hil-trust.js');
const existing = `${{ toJson(steps.find.outputs.comment-body || '') }}`;
const login = '${{ steps.parse.outputs.login }}'.toLowerCase();
const { body } = upsertTrusted(existing, login);
core.setOutput('body', body);
- uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
comment-id: ${{ steps.find.outputs.comment-id }}
body: ${{ steps.upsert.outputs.body }}
edit-mode: replace
- uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
# separate short confirmation comment
body: "Trusted **@${{ steps.parse.outputs.login }}** for this PR. They can now use `/hil quick`, `/hil full` and `/hil <CHIPS>` and their features."
revoke:
if: >
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
(github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'OWNER') &&
startsWith(github.event.comment.body, '/revoke ')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Parse login
id: parse
uses: actions/github-script@v7
with:
script: |
const { parseTrustCommand } = require('./.github/scripts/hil-trust.js');
const res = parseTrustCommand(context.payload.comment.body, 'revoke');
if (res.error) core.setFailed(res.error);
core.setOutput('login', res.login);
- id: find
uses: peter-evans/find-comment@v3
with:
issue-number: ${{ github.event.issue.number }}
comment-author: github-actions[bot]
body-includes: "[HIL trust list]"
- name: Remove from trust list
id: update
uses: actions/github-script@v7
with:
script: |
const { revokeTrusted } = require('./.github/scripts/hil-trust.js');
const existing = `${{ toJson(steps.find.outputs.comment-body || '') }}`;
const login = '${{ steps.parse.outputs.login }}'.toLowerCase();
const { body } = revokeTrusted(existing, login);
core.setOutput('body', body);
- uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
comment-id: ${{ steps.find.outputs.comment-id }}
body: ${{ steps.update.outputs.body }}
edit-mode: replace
- uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: "Revoked **@${{ steps.parse.outputs.login }}** for this PR."
# ---------------------------------------------------------------------------
# SLASH-BASED DISPATCHES (/hil quick, /hil full, /hil <chips...>)
# ---------------------------------------------------------------------------
auth:
# Only PR comments need auth
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
runs-on: ubuntu-latest
outputs:
allowed: ${{ steps.check.outputs.allowed }}
steps:
- id: check
uses: actions/github-script@v7
with:
script: |
const assoc = context.payload.comment.author_association;
const commenter = context.payload.comment.user.login.toLowerCase();
const pr = context.payload.issue.number;
if (assoc === 'MEMBER' || assoc === 'OWNER') {
core.setOutput('allowed', 'true');
return;
}
const { owner, repo } = context.repo;
const comments = await github.paginate(
github.rest.issues.listComments,
{ owner, repo, issue_number: pr, per_page: 100 }
);
const trust = comments.find(c =>
c.user?.login === 'github-actions[bot]' &&
typeof c.body === 'string' &&
c.body.includes('HIL_TRUST_JSON')
);
let allowed = false;
if (trust) {
const m = trust.body.match(/<!--\s*HIL_TRUST_JSON\s*([\s\S]*?)\s*HIL_TRUST_JSON\s*-->/);
if (m && m[1]) {
try {
const data = JSON.parse(m[1]);
const list = (data.trusted || []).map(s => String(s).toLowerCase());
allowed = list.includes(commenter);
} catch {}
}
}
core.setOutput('allowed', allowed ? 'true' : 'false');
hil:
needs: auth
if: github.event_name == 'issue_comment' &&
needs.auth.outputs.allowed == 'true' &&
startsWith(github.event.comment.body, '/hil ')
runs-on: ubuntu-latest
outputs:
run_id: ${{ steps.find-run.outputs.run_id }}
comment_id: ${{ steps.comment.outputs.comment-id }}
kind: ${{ steps.mode.outputs.kind }}
max_polls: ${{ steps.mode.outputs.max_polls }}
steps:
- uses: actions/checkout@v6 # for `require`
with:
fetch-depth: 1
- name: Resolve dispatch parameters
id: mode
uses: actions/github-script@v7
with:
script: |
const { parseChips, parseTests, parsePackage } = require('./.github/scripts/hil-parse.js');
const chips = require('./.github/chips.json');
const body = context.payload.comment.body;
// Even a quick run can legitimately take well over 15 minutes once
// queueing is counted, and a full one always does, so give every
// mode the same 45 minute budget (180 * 15s).
let mode, selected, kind, maxPolls = 180, error = '';
if (body.startsWith('/hil quick')) {
mode = 'quick';
selected = chips.filter(c => c.quick).map(c => c.soc).join(' ');
kind = 'HIL (quick)';
} else if (body.startsWith('/hil full')) {
mode = 'full';
selected = chips.map(c => c.soc).join(' ');
kind = 'HIL (full)';
} else {
mode = 'chips';
const res = parseChips(body);
selected = res.chips;
kind = 'HIL (per-chip)';
error = res.error;
}
core.setOutput('selector', mode === 'chips' ? selected : mode);
core.setOutput('mode', mode);
core.setOutput('chips', selected);
core.setOutput('kind', kind);
core.setOutput('max_polls', String(maxPolls));
core.setOutput('error', error);
core.setOutput('tests', parseTests(body));
core.setOutput('package', parsePackage(body));
- name: Report invalid chips
if: steps.mode.outputs.chips == '' && steps.mode.outputs.error != ''
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
@${{ github.event.comment.user.login }}, HIL **per-chip** request failed: ${{ steps.mode.outputs.error }}
- name: Dispatch HIL
if: steps.mode.outputs.chips != ''
uses: benc-uk/workflow-dispatch@v1
with:
workflow: hil.yml
ref: ${{ github.event.repository.default_branch }}
inputs: |
{
"repository": "${{ github.repository }}",
"branch": "refs/pull/${{ github.event.issue.number }}/head",
"pr_number": "${{ github.event.issue.number }}",
"chips": "${{ steps.mode.outputs.chips }}",
"tests": "${{ steps.mode.outputs.tests }}",
"package": "${{ steps.mode.outputs.package }}",
"distinct_id": "${{ env.DISTINCT_ID }}"
}
- name: Find HIL run URL
if: steps.mode.outputs.chips != ''
id: find-run
uses: actions/github-script@v7
with:
script: |
const { findHilRun } = require('./.github/scripts/hil-find-run.js');
const { runId, body } = await findHilRun({
github,
context,
pr: context.payload.issue.number,
selector: '${{ steps.mode.outputs.selector }}',
distinctId: '${{ env.DISTINCT_ID }}',
});
core.setOutput('run_id', runId);
core.setOutput('body', body);
- name: Confirm in PR
if: steps.mode.outputs.chips != ''
id: comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: ${{ steps.find-run.outputs.body }}
hil-status:
needs: hil
if: needs.hil.outputs.run_id != '' && needs.hil.outputs.comment_id != ''
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6 # for `require`
with:
fetch-depth: 1
- name: Wait for HIL run and update comment
uses: actions/github-script@v7
with:
script: |
const { pollRun } = require('./.github/scripts/hil-status.js');
await pollRun({
github,
context,
runId: Number('${{ needs.hil.outputs.run_id }}'),
commentId: Number('${{ needs.hil.outputs.comment_id }}'),
kind: '${{ needs.hil.outputs.kind }}',
maxPolls: Number('${{ needs.hil.outputs.max_polls }}'),
});
hil-deny:
needs: auth
if:
github.event_name == 'issue_comment' && needs.auth.outputs.allowed != 'true' &&
(startsWith(github.event.comment.body, '/hil ') ||
startsWith(github.event.comment.body, '/test-size'))
runs-on: ubuntu-latest
steps:
- name: Inform not allowed
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
@${{ github.event.comment.user.login }}, sorry — you're not allowed to execute HIL runs or binary size analysis for this PR.
Please ask an `esp-rs` member/owner to grant access with:
```
/trust @${{ github.event.comment.user.login }}
```
After that, you can use `/hil quick`, `/hil full`, `/hil <chips...>` or `/test-size`.
hil-help:
if: github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/hil') &&
!startsWith(github.event.comment.body, '/hil quick') &&
!startsWith(github.event.comment.body, '/hil full') &&
!contains(github.event.comment.body, 'esp32')
runs-on: ubuntu-latest
steps:
- name: Explain usage
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: |
Usage:
- `/hil quick` — run a quick HIL matrix (only `ESP32-S3` (Xtensa) and `ESP32-C6` (RISC-V) tests)
- `/hil full` — run the full HIL matrix for all supported chips
- `/hil <chip1> [<chip2> ...]` — run the full HIL tests **only** for the listed chips
- `/test-size <example_name> [--package <pkg>] <chip1> [chip2 ...]` — run binary size analysis for the specified example on one or more chips. Example: `/test-size embassy_hello_world esp32c3 esp32c6` or `/test-size sleep_timer --package qa esp32c3`
- You can optionally append `--test <name>[,<name>...]` to any `/hil` command to only run selected tests.
- You can optionally include `hil-test-radio` in the comment body of any `/hil` command to run radio HIL instead of the default `hil-test` package.
If you aren't a repository **member/owner**, you must be **trusted for this PR**.
Maintainers can grant access with a `trusted-author` label or with:
```
/trust @<login>
```
and revoke with:
```
/revoke @<login>
```
binary-size:
needs: auth
if: github.event_name == 'issue_comment' &&
needs.auth.outputs.allowed == 'true' &&
startsWith(github.event.comment.body, '/test-size')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6 # for `require`
with:
fetch-depth: 1
- name: Extract parameters from comment
id: extract
env:
COMMENT: ${{ github.event.comment.body }}
run: |
# Expected format: /test-size example_name chip(s)
# Use only the line that holds the command (let users add free-form
# text in the rest of the comment) and strip any CR characters that
# GitHub may include on CRLF line endings.
COMMAND_LINE=$(printf '%s' "$COMMENT" | tr -d '\r' | grep -m1 -E '^/test-size' || true)
if [ -z "$COMMAND_LINE" ]; then
echo "Error: Could not find /test-size command line in comment."
exit 1
fi
# Strip the /test-size prefix
ARGS=$(printf '%s' "$COMMAND_LINE" | sed 's|/test-size[[:space:]]*||')
# Extract --package value if present
PACKAGE=""
if echo "$ARGS" | grep -q '\-\-package'; then
PACKAGE=$(echo "$ARGS" | sed 's/.*--package[[:space:]]\+\([^[:space:]]\+\).*/\1/')
# Remove --package <value> from ARGS for further parsing
ARGS=$(echo "$ARGS" | sed 's/--package[[:space:]]\+[^[:space:]]\+//')
fi
# Known chips — everything matching these is a chip, first token is the example
KNOWN_CHIPS=$(jq -r '[.[].soc] | join(" ")' .github/chips.json)
EXAMPLE_NAME=""
CHIPS_JSON="["
FIRST=true
for token in $ARGS; do
if echo "$KNOWN_CHIPS" | grep -qw "$token"; then
if [ "$FIRST" = "true" ]; then
CHIPS_JSON="${CHIPS_JSON}\"${token}\""
FIRST=false
else
CHIPS_JSON="${CHIPS_JSON},\"${token}\""
fi
elif [ -z "$EXAMPLE_NAME" ]; then
EXAMPLE_NAME="$token"
fi
done
CHIPS_JSON="${CHIPS_JSON}]"
if [ -z "$EXAMPLE_NAME" ]; then
echo "Error: No example name provided."
echo "Expected: /test-size example_name [--package pkg] chip1 [chip2 ...]"
exit 1
fi
if [ "$CHIPS_JSON" = "[]" ]; then
echo "Error: No valid chip names provided."
echo "Valid chips: $KNOWN_CHIPS"
exit 1
fi
echo "example_name=$EXAMPLE_NAME" >> $GITHUB_OUTPUT
echo "package=$PACKAGE" >> $GITHUB_OUTPUT
echo "chips=$CHIPS_JSON" >> $GITHUB_OUTPUT
CHIPS_ESCAPED=$(echo "$CHIPS_JSON" | sed 's/"/\\"/g')
echo "chips_escaped=$CHIPS_ESCAPED" >> $GITHUB_OUTPUT
echo "Parsed — example: $EXAMPLE_NAME | package: $PACKAGE | chips: $CHIPS_JSON"
- name: Confirm in PR
id: comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number }}
body: >
Triggered binary size analysis for
`${{ steps.extract.outputs.example_name }}`
on chips `${{ steps.extract.outputs.chips }}`
for #${{ github.event.issue.number }}.
Results will be posted as a comment when ready.
- name: Dispatch Binary Size Analysis
uses: benc-uk/workflow-dispatch@v1
with:
workflow: binary-size.yml
ref: ${{ github.event.repository.default_branch }}
inputs: '{"pr_number":"${{ github.event.issue.number }}","comment_id":"${{ steps.comment.outputs.comment-id }}","example_name":"${{ steps.extract.outputs.example_name }}","package":"${{ steps.extract.outputs.package }}","chips":"${{ steps.extract.outputs.chips_escaped }}","distinct_id":"${{ env.DISTINCT_ID }}"}'
- name: Find binary size run URL
id: find-run
uses: actions/github-script@v7
with:
script: |
const { findDispatchedRun } = require('./.github/scripts/hil-find-run.js');
const run = await findDispatchedRun({
github,
context,
workflowId: 'binary-size.yml',
distinctId: '${{ env.DISTINCT_ID }}',
});
core.setOutput('url', run?.html_url || '');
- name: Add run URL to comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.comment.outputs.comment-id }}
body: >
Triggered **binary size analysis** for #${{ github.event.issue.number }}
(example: `${{ steps.extract.outputs.example_name }}`, chips: `${{ steps.extract.outputs.chips }}`).
Run: ${{ steps.find-run.outputs.url != '' && steps.find-run.outputs.url || 'could not be determined yet; check the Binary Size Analysis workflow runs manually.' }}
edit-mode: replace