Repository navigation
135 lines (127 loc) · 6.33 KB
/
Copy pathrelease-recheck.yml
File metadata and controls
135 lines (127 loc) · 6.33 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
# Copyright (c) Meta Platforms, Inc. and affiliates.
# The release owner's re-check of main's tip (spec:AST-030 FR23). A
# maintainer dispatches it with the exact commit, usually right after a fix
# lands during a release. It starts at once, ahead of everything else:
# - ci.yml's canonical release-check (visual, accessibility, RTL, typecheck,
# registry) in its wide shards, which takes the main check lane, cancelling
# any check running there;
# - the Main workflow's full unit run on main's tip, which takes the
# validation group the same way.
#
# Both kinds are for main's tip only: a re-check cancels what runs in main's
# lanes, so an older commit's re-check would cancel the tip's checks.
#
# With `failed-only`, it re-runs just the failed or cancelled jobs of this
# commit's latest re-check runs, found by their "Mark a release re-check" step,
# so an hourly check of the same commit is never mistaken for one. It finds both
# runs before it re-runs either. That is sound because it is the same commit:
# each run's passing jobs already checked it, so a run whose re-run passes is
# a full passing check of that commit, which is what the release publish
# requires. A fix is a new commit and gets a full re-check.
name: Release re-check
on:
workflow_dispatch:
inputs:
sha:
description: "Full SHA of main's tip to re-check"
type: string
required: true
failed-only:
description: "Re-run only the failed jobs of this commit's latest re-check"
type: boolean
default: false
permissions: {}
jobs:
recheck:
runs-on: ubuntu-slim
timeout-minutes: 5
permissions:
actions: write
contents: read
steps:
- name: Start the re-check
uses: actions/github-script@v9
env:
SHA: ${{ inputs.sha }}
FAILED_ONLY: ${{ inputs['failed-only'] }}
with:
script: |
const sha = (process.env.SHA ?? '').trim();
const failedOnly = process.env.FAILED_ONLY === 'true';
const actor = process.env.GITHUB_TRIGGERING_ACTOR || context.actor;
const WORKFLOWS = ['ci.yml', 'deploy.yml'];
// Maintainers only: dispatching needs write access already, and a
// re-check cancels main's running checks.
const {data: permission} = await github.rest.repos.getCollaboratorPermissionLevel({
...context.repo, username: actor,
});
if (!['admin', 'maintain'].includes(permission.role_name)) {
throw new Error(`Only a maintainer can re-check a release; ${actor} has the ${permission.role_name} role.`);
}
if (context.ref !== 'refs/heads/main') {
throw new Error('Dispatch the release re-check from main.');
}
if (!/^[0-9a-f]{40}$/.test(sha)) {
throw new Error(`sha must be a full 40-character commit SHA, got "${sha}".`);
}
// A re-check takes main's lanes, cancelling what runs there, so it
// is only for main's tip: a release-check binds the tip when it
// starts (ci.yml's main authority), and re-running an older
// commit's failed jobs would cancel the newer tip's checks.
const {data: main} = await github.rest.repos.getBranch({...context.repo, branch: 'main'});
if (main.commit.sha !== sha) {
throw new Error(`main is at ${main.commit.sha}, not ${sha}; re-check main's tip.`);
}
if (failedOnly) {
const MARK = 'Mark a release re-check';
const runs = [];
for (const workflow_id of WORKFLOWS) {
const {data} = await github.rest.actions.listWorkflowRuns({
...context.repo, workflow_id, event: 'workflow_dispatch', branch: 'main', head_sha: sha, per_page: 20,
});
let run;
// Newest first; a run is a re-check when its marker step ran.
for (const candidate of data.workflow_runs) {
if (candidate.actor?.login !== 'github-actions[bot]') continue;
const {data: {jobs}} = await github.rest.actions.listJobsForWorkflowRun({
...context.repo, run_id: candidate.id, filter: 'latest', per_page: 100,
});
if (jobs.some(job => job.steps?.some(step => step.name === MARK && step.conclusion === 'success'))) {
run = candidate;
break;
}
}
if (run == null) {
throw new Error(`No re-check of ${sha.slice(0, 7)} in ${workflow_id}; dispatch a full re-check.`);
}
if (run.status !== 'completed') {
throw new Error(`${workflow_id} re-check ${run.html_url} is still ${run.status}.`);
}
runs.push({workflow_id, run});
}
for (const {workflow_id, run} of runs) {
if (run.conclusion === 'success') {
core.info(`${workflow_id}: ${run.html_url} already passed.`);
continue;
}
await github.rest.actions.reRunWorkflowFailedJobs({...context.repo, run_id: run.id});
core.notice(`${workflow_id}: re-running the failed jobs of ${run.html_url}.`);
}
return;
}
await github.rest.actions.createWorkflowDispatch({
...context.repo, workflow_id: 'ci.yml', ref: 'main',
// Cut evidence: the run is named Release evidence of <sha>.
inputs: {operation: 'release-check', 'release-branch': 'main', 'expected-head': sha, recheck: 'true', evidence: 'true'},
});
await github.rest.actions.createWorkflowDispatch({
...context.repo, workflow_id: 'deploy.yml', ref: 'main',
// Naming the commit, so the run is the commit's unit-run receipt
// (spec:AST-030 FR21); a re-check takes the unit-run group.
inputs: {sha, recheck: 'true'},
});
await core.summary
.addHeading('Release re-check started')
.addRaw(`Commit: ${sha}\n\n`)
.addRaw('Started the canonical release-check (ci.yml) and the full unit run (Main) on this commit. Each takes its lane at once.')
.write();