Repository navigation
652 lines (621 loc) · 28.1 KB
/
Copy pathpr-comment.yml
File metadata and controls
652 lines (621 loc) · 28.1 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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
# Copyright (c) Meta Platforms, Inc. and affiliates.
# PR Analysis Report — posts/updates the analysis comment for ALL PRs.
#
# Runs on workflow_run after CI completes, NOT on pull_request. That matters:
# a pull_request workflow triggered by a fork gets a READ-ONLY token and can't
# comment, which is why the report never appeared on external-contributor PRs.
# workflow_run runs from the base repo with the repo's own token (pull-requests:
# write), so it can comment on fork PRs too — one code path for every PR, no
# drift between a fork path and a same-repo path.
#
# Safety: resolves scope and PR identity from the GitHub API. Privileged jobs
# check out only trusted default-branch code. Both preview links are the
# branch's Vercel alias, known without waiting for a deployment.
name: PR Comment
on:
workflow_run:
workflows: ['CI']
types: [completed]
permissions: {}
jobs:
resolve:
if: github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request'
runs-on: ubuntu-slim
permissions:
contents: read
pull-requests: read
outputs:
valid: ${{ steps.identity.outputs.valid }}
pr_number: ${{ steps.identity.outputs.pr_number }}
head_sha: ${{ steps.identity.outputs.head_sha }}
head_repo: ${{ steps.identity.outputs.head_repo }}
head_repo_id: ${{ steps.identity.outputs.head_repo_id }}
head_ref: ${{ steps.identity.outputs.head_ref }}
base_repo: ${{ steps.identity.outputs.base_repo }}
base_sha: ${{ steps.identity.outputs.base_sha }}
run_id: ${{ steps.identity.outputs.run_id }}
run_attempt: ${{ steps.identity.outputs.run_attempt }}
source_conclusion: ${{ steps.identity.outputs.source_conclusion }}
spec_only: ${{ steps.identity.outputs.spec_only }}
tooling_only: ${{ steps.identity.outputs.tooling_only }}
failed: ${{ steps.checkout.outcome == 'failure' || steps.identity.outcome == 'failure' }}
steps:
- name: Checkout trusted default-branch code
id: checkout
continue-on-error: true
uses: actions/checkout@v7
with:
ref: main
- name: Resolve trusted PR identity
continue-on-error: true
id: identity
# Steps continue on error, so a failed checkout no longer skips this
# one by itself.
if: steps.checkout.outcome == 'success'
uses: actions/github-script@v9
with:
retries: 3
script: |
// Wait out the repository's shared API rate limit (lib/rate-limit-backoff.cjs).
require(require('node:path').join(process.env.GITHUB_WORKSPACE, '.github/scripts/lib/rate-limit-backoff.cjs'))
.installRateLimitBackoff({github, core});
const {pathToFileURL} = require('node:url');
const {resolveWorkflowRunPullRequest} = await import(
pathToFileURL(`${process.env.GITHUB_WORKSPACE}/.github/scripts/lib/pr-preview.mjs`).href
);
const identity = await resolveWorkflowRunPullRequest({
github,
...context.repo,
run: context.payload.workflow_run,
});
if (identity === null) {
core.notice(
`Skipping source run ${context.payload.workflow_run.id}: no open pull request remains for this head.`,
);
core.setOutput('valid', 'false');
return;
}
const path = require('node:path');
const {classifyChanges} = require(path.join(
process.env.GITHUB_WORKSPACE,
'.github/scripts/change-scope.cjs',
));
const {data: pull} = await github.rest.pulls.get({
...context.repo,
pull_number: identity.prNumber,
});
const files = await github.paginate(github.rest.pulls.listFiles, {
...context.repo,
pull_number: identity.prNumber,
per_page: 100,
});
const changeScope = classifyChanges(files, {
expectedCount: pull.changed_files,
});
core.setOutput('valid', 'true');
core.setOutput('pr_number', String(identity.prNumber));
core.setOutput('head_sha', identity.headSha);
core.setOutput('head_repo', identity.headRepository);
core.setOutput('head_repo_id', identity.headRepositoryId);
core.setOutput('head_ref', identity.headRef);
core.setOutput('base_repo', identity.baseRepository);
core.setOutput('base_sha', identity.baseSha);
core.setOutput('run_id', String(identity.sourceRunId));
core.setOutput('run_attempt', String(identity.sourceRunAttempt));
core.setOutput('source_conclusion', identity.sourceConclusion);
core.setOutput('spec_only', String(changeScope.specOnly));
core.setOutput('tooling_only', String(changeScope.toolingOnly));
spec-only-reconcile:
needs: resolve
concurrency:
group: pr-report-${{ needs.resolve.outputs.pr_number }}
cancel-in-progress: false
if: >-
github.event.action == 'completed' &&
needs.resolve.outputs.valid == 'true' &&
(needs.resolve.outputs.spec_only == 'true' ||
needs.resolve.outputs.tooling_only == 'true')
runs-on: ubuntu-slim
permissions:
actions: read
contents: read
pull-requests: write
outputs:
failed: ${{ steps.scope.outcome == 'failure' || steps.checkout.outcome == 'failure' || steps.reconcile.outcome == 'failure' }}
steps:
- name: Report no visual scope
id: scope
continue-on-error: true
run: echo 'No visual scope applies; canonical visual checks are not applicable.' >> "$GITHUB_STEP_SUMMARY"
- name: Checkout trusted default-branch code
id: checkout
continue-on-error: true
uses: actions/checkout@v7
with:
ref: main
- name: Remove stale preview links from an existing report
id: reconcile
continue-on-error: true
if: steps.checkout.outcome == 'success'
uses: actions/github-script@v9
env:
PR_NUMBER: ${{ needs.resolve.outputs.pr_number }}
HEAD_SHA: ${{ needs.resolve.outputs.head_sha }}
HEAD_REPOSITORY: ${{ needs.resolve.outputs.head_repo }}
HEAD_REPOSITORY_ID: ${{ needs.resolve.outputs.head_repo_id }}
HEAD_REF: ${{ needs.resolve.outputs.head_ref }}
BASE_REPOSITORY: ${{ needs.resolve.outputs.base_repo }}
BASE_SHA: ${{ needs.resolve.outputs.base_sha }}
RUN_ID: ${{ needs.resolve.outputs.run_id }}
RUN_ATTEMPT: ${{ needs.resolve.outputs.run_attempt }}
SOURCE_CONCLUSION: ${{ needs.resolve.outputs.source_conclusion }}
with:
retries: 3
script: |
// Wait out the repository's shared API rate limit (lib/rate-limit-backoff.cjs).
require(require('node:path').join(process.env.GITHUB_WORKSPACE, '.github/scripts/lib/rate-limit-backoff.cjs'))
.installRateLimitBackoff({github, core});
const {pathToFileURL} = require('node:url');
const {reconcilePrComment} = await import(
pathToFileURL(`${process.env.GITHUB_WORKSPACE}/.github/scripts/lib/pr-preview.mjs`).href
);
await reconcilePrComment({
github,
core,
context,
expectedIdentity: {
prNumber: Number(process.env.PR_NUMBER),
headSha: process.env.HEAD_SHA,
headRepository: process.env.HEAD_REPOSITORY,
headRepositoryId: process.env.HEAD_REPOSITORY_ID,
headRef: process.env.HEAD_REF,
baseRepository: process.env.BASE_REPOSITORY,
baseSha: process.env.BASE_SHA,
sourceRunId: Number(process.env.RUN_ID),
sourceRunAttempt: Number(process.env.RUN_ATTEMPT),
sourceConclusion: process.env.SOURCE_CONCLUSION,
},
createIfMissing: false,
fallbackMessage:
'The current change has no visual or preview-producing scope. Visual checks are not applicable; preview links are not shown.',
});
# The changed visual frames behind the report's thumbnails, on the pull
# request's assets branch. The only job here that writes repository
# contents: it runs trusted code from main (never pull-request code), keeps
# no credentials in its checkout, and publish-frames.mjs writes only
# assets/pr-<n>, and only validated PNG/WebP frames.
frames:
needs: resolve
concurrency:
group: pr-frames-${{ needs.resolve.outputs.pr_number }}
cancel-in-progress: false
if: >-
always() &&
github.event.action == 'completed' &&
needs.resolve.outputs.valid == 'true' &&
needs.resolve.outputs.spec_only != 'true' &&
needs.resolve.outputs.tooling_only != 'true'
runs-on: ubuntu-24.04-arm
permissions:
actions: read
contents: write
outputs:
image_base: ${{ steps.frames.outputs.image_base }}
published: ${{ steps.frames.outputs.published }}
failed: >-
${{ steps.checkout.outcome == 'failure' ||
steps.setup.outcome == 'failure' ||
steps.visual.outcome == 'failure' ||
steps.frames.outcome == 'failure' }}
steps:
- name: Checkout trusted default-branch code
id: checkout
continue-on-error: true
uses: actions/checkout@v7
with:
ref: main
persist-credentials: false
- name: Setup Node and pnpm
id: setup
continue-on-error: true
if: steps.checkout.outcome == 'success'
uses: ./.github/actions/setup
- name: Download canonical visual report
id: visual-download
if: steps.setup.outcome == 'success'
uses: actions/download-artifact@v8
with:
name: visual-pr-report
path: visual-pr-report
run-id: ${{ needs.resolve.outputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
# The same re-encoding the comment job applies: only JSON and
# re-encoded PNGs from the exact CI attempt.
- name: Prepare canonical visual report
id: visual
continue-on-error: true
if: steps.visual-download.outcome == 'success'
env:
HEAD_SHA: ${{ needs.resolve.outputs.head_sha }}
RUN_ID: ${{ needs.resolve.outputs.run_id }}
RUN_ATTEMPT: ${{ needs.resolve.outputs.run_attempt }}
run: |
node .github/scripts/visual-gate/publish-pr-report.mjs \
--input visual-pr-report \
--output trusted-visual \
--head-sha "$HEAD_SHA" \
--run-id "$RUN_ID" \
--run-attempt "$RUN_ATTEMPT"
- name: Publish changed visual frames
id: frames
continue-on-error: true
if: steps.visual.outcome == 'success'
env:
GITHUB_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ needs.resolve.outputs.pr_number }}
HEAD_SHA: ${{ needs.resolve.outputs.head_sha }}
run: |
node .github/scripts/visual-gate/publish-frames.mjs \
--input trusted-visual \
--pr "$PR_NUMBER" \
--head-sha "$HEAD_SHA" \
--repository "$GITHUB_REPOSITORY" \
--limit 12
comment:
needs: [resolve, frames]
concurrency:
group: pr-report-${{ needs.resolve.outputs.pr_number }}
cancel-in-progress: false
# Storybook and Sandbox links are the branch's Vercel alias.
# Visual evidence remains attached to the exact CI run.
if: >-
always() &&
github.event.action == 'completed' &&
needs.resolve.outputs.valid == 'true' &&
needs.resolve.outputs.spec_only != 'true' &&
needs.resolve.outputs.tooling_only != 'true'
runs-on: ubuntu-24.04-arm
permissions:
pull-requests: write
# actions: the artifacts and the source run's job list; deployments:
# this head's Vercel preview state.
actions: read
deployments: read
# The artifact downloads are optional (a run may not produce them), so
# they are not failures of this job.
outputs:
failed: >-
${{ steps.checkout.outcome == 'failure' ||
steps.setup.outcome == 'failure' ||
steps.identity.outcome == 'failure' ||
steps.cross-check.outcome == 'failure' ||
steps.visual.outcome == 'failure' ||
steps.inherited.outcome == 'failure' ||
steps.ci-history.outcome == 'failure' ||
steps.publish.outcome == 'failure' }}
steps:
- name: Checkout trusted default-branch code
id: checkout
continue-on-error: true
uses: actions/checkout@v7
with:
ref: main
- name: Setup Node and pnpm
id: setup
continue-on-error: true
uses: ./.github/actions/setup
# Recheck the exact source run and current PR immediately before any
# privileged report or status mutation.
- name: Reconfirm trusted PR identity
continue-on-error: true
id: identity
# Steps continue on error, so a failed checkout or install no longer
# skips the rest by itself. Every later step requires a valid identity.
if: steps.setup.outcome == 'success'
uses: actions/github-script@v9
env:
PR_NUMBER: ${{ needs.resolve.outputs.pr_number }}
HEAD_SHA: ${{ needs.resolve.outputs.head_sha }}
HEAD_REPOSITORY: ${{ needs.resolve.outputs.head_repo }}
HEAD_REPOSITORY_ID: ${{ needs.resolve.outputs.head_repo_id }}
HEAD_REF: ${{ needs.resolve.outputs.head_ref }}
BASE_REPOSITORY: ${{ needs.resolve.outputs.base_repo }}
SOURCE_RUN_ID: ${{ needs.resolve.outputs.run_id }}
SOURCE_RUN_ATTEMPT: ${{ needs.resolve.outputs.run_attempt }}
SOURCE_CONCLUSION: ${{ needs.resolve.outputs.source_conclusion }}
with:
retries: 3
script: |
// Wait out the repository's shared API rate limit (lib/rate-limit-backoff.cjs).
require(require('node:path').join(process.env.GITHUB_WORKSPACE, '.github/scripts/lib/rate-limit-backoff.cjs'))
.installRateLimitBackoff({github, core});
const {pathToFileURL} = require('node:url');
const {confirmOrStandDown} = await import(
pathToFileURL(`${process.env.GITHUB_WORKSPACE}/.github/scripts/lib/pr-preview.mjs`).href
);
const identity = await confirmOrStandDown({
github,
core,
...context.repo,
expected: {
prNumber: Number(process.env.PR_NUMBER),
headSha: process.env.HEAD_SHA,
headRepository: process.env.HEAD_REPOSITORY,
headRepositoryId: process.env.HEAD_REPOSITORY_ID,
headRef: process.env.HEAD_REF,
baseRepository: process.env.BASE_REPOSITORY,
sourceRunId: Number(process.env.SOURCE_RUN_ID),
sourceRunAttempt: Number(process.env.SOURCE_RUN_ATTEMPT),
sourceConclusion: process.env.SOURCE_CONCLUSION,
},
});
if (identity === null) {
core.setOutput('valid', 'false');
return;
}
core.setOutput('valid', 'true');
core.setOutput('pr_number', String(identity.prNumber));
core.setOutput('head_sha', identity.headSha);
core.setOutput('head_repo', identity.headRepository);
core.setOutput('head_repo_id', identity.headRepositoryId);
core.setOutput('head_ref', identity.headRef);
core.setOutput('base_repo', identity.baseRepository);
core.setOutput('base_sha', identity.baseSha);
core.setOutput('run_id', String(identity.sourceRunId));
core.setOutput('run_attempt', String(identity.sourceRunAttempt));
core.setOutput('source_conclusion', identity.sourceConclusion);
- name: Download analysis artifact from the CI run
if: steps.identity.outputs.valid == 'true'
uses: actions/download-artifact@v8
with:
name: pr-analysis
path: pr-analysis
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Download base size stats from the CI run
if: steps.identity.outputs.valid == 'true'
uses: actions/download-artifact@v8
with:
name: pr-size-base
path: pr-size-base
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
# The touched-components check's per-component results (or its wide-
# change flag); absent when the check did not run.
- name: Download the touched-components report from the CI run
if: steps.identity.outputs.valid == 'true'
uses: actions/download-artifact@v8
with:
name: touched-components
path: touched-components
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Download a11y artifact from the CI run
if: steps.identity.outputs.valid == 'true'
uses: actions/download-artifact@v8
with:
name: a11y-report
path: a11y
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Download canonical visual report
id: visual-download
if: steps.identity.outputs.valid == 'true'
uses: actions/download-artifact@v8
with:
name: visual-pr-report
path: visual-pr-report
run-id: ${{ steps.identity.outputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
# A failed run may be a deferred agent-lane push (spec:AST-030 FR20),
# whose report says so instead of an unavailable analysis.
- name: Download the heavy-CI deferral from the CI run
id: deferral-download
if: steps.identity.outputs.valid == 'true' && steps.identity.outputs.source_conclusion == 'failure'
uses: actions/download-artifact@v8
with:
name: heavy-ci-deferred-${{ steps.identity.outputs.run_attempt }}
path: heavy-ci-deferred
run-id: ${{ steps.identity.outputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Cross-check artifact identity
id: cross-check
continue-on-error: true
if: steps.identity.outputs.valid == 'true' && hashFiles('pr-analysis/pr-meta.json') != ''
env:
EXPECTED_PR: ${{ steps.identity.outputs.pr_number }}
EXPECTED_HEAD: ${{ steps.identity.outputs.head_sha }}
EXPECTED_HEAD_REPO: ${{ steps.identity.outputs.head_repo }}
EXPECTED_BASE_REPO: ${{ steps.identity.outputs.base_repo }}
EXPECTED_RUN: ${{ steps.identity.outputs.run_id }}
EXPECTED_ATTEMPT: ${{ steps.identity.outputs.run_attempt }}
run: |
node --input-type=module - <<'NODE'
import fs from 'node:fs';
import {validateAnalysisMetadata} from './.github/scripts/lib/pr-preview.mjs';
const metadata = JSON.parse(fs.readFileSync('pr-analysis/pr-meta.json', 'utf8'));
validateAnalysisMetadata(metadata, {
prNumber: process.env.EXPECTED_PR,
headSha: process.env.EXPECTED_HEAD,
headRepository: process.env.EXPECTED_HEAD_REPO,
baseRepository: process.env.EXPECTED_BASE_REPO,
sourceRunId: process.env.EXPECTED_RUN,
sourceRunAttempt: process.env.EXPECTED_ATTEMPT,
});
NODE
# Only JSON and re-encoded PNGs from the exact CI attempt are published.
# No browser, baseline comparison, acceptance, or status authority lives here.
- name: Prepare canonical visual report
id: visual
continue-on-error: true
if: steps.identity.outputs.valid == 'true' && steps.visual-download.outcome == 'success'
env:
HEAD_SHA: ${{ steps.identity.outputs.head_sha }}
RUN_ID: ${{ steps.identity.outputs.run_id }}
RUN_ATTEMPT: ${{ steps.identity.outputs.run_attempt }}
run: |
node .github/scripts/visual-gate/publish-pr-report.mjs \
--input visual-pr-report \
--output trusted-visual \
--head-sha "$HEAD_SHA" \
--run-id "$RUN_ID" \
--run-attempt "$RUN_ATTEMPT"
# Marks a changed shot that a merged pull request already in this head
# also changed, with the same image, as inherited from main (at most 20
# API calls).
# Report text only: no check or status reads it.
- name: Mark inherited visual changes
id: inherited
continue-on-error: true
if: steps.identity.outputs.valid == 'true' && steps.visual.outcome == 'success'
env:
GITHUB_TOKEN: ${{ github.token }}
HEAD_REF: ${{ steps.identity.outputs.head_ref }}
HEAD_SHA: ${{ steps.identity.outputs.head_sha }}
run: |
node .github/scripts/visual-gate/inherited-shots.mjs \
--verdict trusted-visual/verdict.json \
--manifest visual-pr-report/manifest.json \
--head-ref "$HEAD_REF" \
--head-sha "$HEAD_SHA"
# The CI-impact baseline (recent pull-request runs) is read once a day
# and kept as an artifact, so later CI-changing PRs that day reuse it.
- name: Find today's CI history
id: ci-history
continue-on-error: true
if: steps.identity.outputs.valid == 'true'
uses: actions/github-script@v9
with:
retries: 3
script: |
// Wait out the repository's shared API rate limit (lib/rate-limit-backoff.cjs).
require(require('node:path').join(process.env.GITHUB_WORKSPACE, '.github/scripts/lib/rate-limit-backoff.cjs'))
.installRateLimitBackoff({github, core});
// Only this repository's own runs on main keep the history, at any
// commit (lib/main-artifact.cjs).
const {mainArtifactRunId} = require(`${process.env.GITHUB_WORKSPACE}/.github/scripts/lib/main-artifact.cjs`);
const name = `ci-history-${new Date().toISOString().slice(0, 10)}`;
const runId = await mainArtifactRunId({github, ...context.repo, name});
core.setOutput('name', name);
core.setOutput('run_id', runId ?? '');
- name: Download today's CI history
if: steps.identity.outputs.valid == 'true' && steps.ci-history.outputs.run_id != ''
continue-on-error: true
uses: actions/download-artifact@v8
with:
name: ${{ steps.ci-history.outputs.name }}
run-id: ${{ steps.ci-history.outputs.run_id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ci-history
- name: Generate and post PR comment
id: publish
continue-on-error: true
if: always() && steps.identity.outputs.valid == 'true'
uses: actions/github-script@v9
env:
PR_NUMBER: ${{ steps.identity.outputs.pr_number }}
HEAD_SHA: ${{ steps.identity.outputs.head_sha }}
HEAD_REPOSITORY: ${{ steps.identity.outputs.head_repo }}
HEAD_REPOSITORY_ID: ${{ steps.identity.outputs.head_repo_id }}
HEAD_REF: ${{ steps.identity.outputs.head_ref }}
BASE_REPOSITORY: ${{ steps.identity.outputs.base_repo }}
BASE_SHA: ${{ steps.identity.outputs.base_sha }}
RUN_ID: ${{ steps.identity.outputs.run_id }}
RUN_ATTEMPT: ${{ steps.identity.outputs.run_attempt }}
SOURCE_CONCLUSION: ${{ steps.identity.outputs.source_conclusion }}
VISUAL_IMAGE_BASE: ${{ needs.frames.outputs.image_base }}
VISUAL_PUBLISHED: ${{ needs.frames.outputs.published }}
with:
retries: 3
script: |
// Wait out the repository's shared API rate limit (lib/rate-limit-backoff.cjs).
require(require('node:path').join(process.env.GITHUB_WORKSPACE, '.github/scripts/lib/rate-limit-backoff.cjs'))
.installRateLimitBackoff({github, core});
const {pathToFileURL} = require('node:url');
const {reconcilePrComment} = await import(
pathToFileURL(`${process.env.GITHUB_WORKSPACE}/.github/scripts/lib/pr-preview.mjs`).href
);
await reconcilePrComment({
github,
core,
context,
expectedIdentity: {
prNumber: Number(process.env.PR_NUMBER),
headSha: process.env.HEAD_SHA,
headRepository: process.env.HEAD_REPOSITORY,
headRepositoryId: process.env.HEAD_REPOSITORY_ID,
headRef: process.env.HEAD_REF,
baseRepository: process.env.BASE_REPOSITORY,
baseSha: process.env.BASE_SHA,
sourceRunId: Number(process.env.RUN_ID),
sourceRunAttempt: Number(process.env.RUN_ATTEMPT),
sourceConclusion: process.env.SOURCE_CONCLUSION,
},
fallbackMessage: require('node:fs').existsSync('heavy-ci-deferred/heavy-ci-deferred.json')
? 'Heavy CI deferred: runs when review passes and before merge. Lint, typecheck and any path-filtered checks ran on this push.'
: undefined,
visualFrames: {
imageBase: process.env.VISUAL_IMAGE_BASE,
published: process.env.VISUAL_PUBLISHED,
},
});
- name: Keep today's CI history
if: steps.identity.outputs.valid == 'true' && steps.ci-history.outputs.name != '' && steps.ci-history.outputs.run_id == '' && hashFiles('ci-history/ci-history.json') != ''
continue-on-error: true
uses: actions/upload-artifact@v7
with:
name: ${{ steps.ci-history.outputs.name }}
path: ci-history/ci-history.json
retention-days: 2
# The CI-completion lane runs on workflow_run, so GitHub attaches its jobs to
# main's latest commit. Main's checks must show main's health, not a pull
# request's. The jobs above therefore never fail the run: every fallible step
# continues on error, and this job reports their outcome as the PR Comment
# status on the pull request's own head.
report:
needs: [resolve, spec-only-reconcile, frames, comment]
if: >-
always() &&
github.event_name == 'workflow_run' &&
github.event.workflow_run.event == 'pull_request' &&
(needs.resolve.outputs.valid == 'true' ||
needs.resolve.outputs.failed == 'true')
runs-on: ubuntu-slim
permissions:
statuses: write
steps:
- name: Report the outcome on the pull request head
continue-on-error: true
uses: actions/github-script@v9
env:
# The source run's head is the pull request head it tested, taken from
# the trusted event rather than from any job output.
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
FAILED: >-
${{ needs.resolve.outputs.failed == 'true' ||
needs.spec-only-reconcile.outputs.failed == 'true' ||
needs.frames.outputs.failed == 'true' ||
needs.comment.outputs.failed == 'true' ||
contains(needs.*.result, 'failure') ||
contains(needs.*.result, 'cancelled') }}
with:
retries: 3
script: |
const failed = process.env.FAILED === 'true';
await github.rest.repos.createCommitStatus({
...context.repo,
sha: process.env.HEAD_SHA,
context: 'PR Comment',
state: failed ? 'failure' : 'success',
target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
description: failed
? 'A PR report step failed or was cancelled. See the run.'
: 'No PR report step failed.',
});