Skip to content

Commit 4f454a7

Browse files
cloud-fanIsaac
andcommitted
Isolate per-PR sync failures in update_build_status.yml
A failed check-run listing or PATCH on one PR no longer aborts the whole scheduled pass and leaves every later PR unsynced. Each failure, including a failed backfill, now skips only that PR (retried on the next pass), and the step fails after the pass so a recurring error, such as a 422 on a value the endpoint rejects, stays visible instead of hiding in the log of a green run. Co-authored-by: Isaac <[email protected]>
1 parent 9f5b3ae commit 4f454a7

1 file changed

Lines changed: 39 additions & 6 deletions

File tree

‎.github/workflows/update_build_status.yml‎

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,41 @@ jobs:
112112
const isActionRequiredBuildCheck = (cr) =>
113113
cr.name == 'Build' && cr.conclusion == 'action_required';
114114
115+
// PRs whose sync failed on this pass. A failed call skips only that PR (it is retried
116+
// on the next pass) instead of aborting the whole scheduled run and leaving every PR
117+
// later in the iteration unsynced. The step still fails after the pass, so an error
118+
// that keeps recurring (e.g. a 422 for a value the endpoint rejects) stays visible
119+
// instead of hiding in the log of a green run.
120+
const failedPRs = new Set();
121+
122+
// PATCH a Build check-run, recording a failure against the PR instead of throwing.
123+
const updateCheckRun = async (pr, body) => {
124+
try {
125+
await github.request('PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}', body);
126+
} catch (error) {
127+
console.error(' Updating check run ' + body.check_run_id + ' failed; '
128+
+ 'will retry next pass');
129+
console.error(error);
130+
failedPRs.add(pr.number);
131+
}
132+
};
133+
115134
// Iterate open PRs
116135
for await (const prs of github.paginate.iterator(endpoint,params)) {
117136
// Each page
118137
for await (const pr of prs.data) {
119138
console.log('SHA: ' + pr.head.sha)
120139
console.log(' Mergeable status: ' + pr.mergeable_state)
121140
if (pr.mergeable_state == null || maybeReady.includes(pr.mergeable_state)) {
122-
const checkRuns = await listCheckRuns(pr.head.sha)
141+
let checkRuns
142+
try {
143+
checkRuns = await listCheckRuns(pr.head.sha)
144+
} catch (error) {
145+
console.error(' Listing check runs failed for this PR; will retry next pass')
146+
console.error(error)
147+
failedPRs.add(pr.number)
148+
continue
149+
}
123150
124151
// Does this SHA already carry an action_required Build check? notify (or an
125152
// earlier pass of this updater) writes one when no fork run was found. It is
@@ -188,7 +215,7 @@ jobs:
188215
const conclusion = conclusions.includes(run.data.conclusion)
189216
? run.data.conclusion : 'failure'
190217
console.log(' Run ' + cr.id + ': set status (' + run.data.status + ') and conclusion (' + run.data.conclusion + ' -> ' + conclusion + ')')
191-
const response = await github.request('PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}', {
218+
await updateCheckRun(pr, {
192219
owner: context.repo.owner,
193220
repo: context.repo.repo,
194221
check_run_id: cr.id,
@@ -202,7 +229,7 @@ jobs:
202229
// but workflow_run may also report requested / waiting / pending.
203230
const status = run.data.status == 'in_progress' ? 'in_progress' : 'queued'
204231
console.log(' Run ' + cr.id + ': set status (' + run.data.status + ' -> ' + status + ')')
205-
const response = await github.request('PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}', {
232+
await updateCheckRun(pr, {
206233
owner: context.repo.owner,
207234
repo: context.repo.repo,
208235
check_run_id: cr.id,
@@ -309,9 +336,9 @@ jobs:
309336
// even though its output still parses as syncable, so it too is excluded.
310337
//
311338
// The recheck listing and the create below are wrapped so a failure on one
312-
// PR degrades to "skip this PR, retry next pass" rather than aborting the
313-
// whole scheduled run and starving every PR later in the iteration - the same
314-
// reason the sync loop above guards its calls.
339+
// PR degrades to "skip this PR, retry next pass" (see failedPRs) rather than
340+
// aborting the whole scheduled run and starving every PR later in the
341+
// iteration - the same reason the sync loop above guards its calls.
315342
try {
316343
const recheck = await listCheckRuns(pr.head.sha)
317344
const existingBuild = recheck.some(cr =>
@@ -387,9 +414,15 @@ jobs:
387414
} catch (error) {
388415
console.error(' Backfill failed for this PR; will retry next pass')
389416
console.error(error)
417+
failedPRs.add(pr.number)
390418
continue
391419
}
392420
}
393421
}
394422
}
395423
}
424+
425+
if (failedPRs.size > 0) {
426+
core.setFailed('Failed to sync ' + failedPRs.size + ' PR(s), will retry next pass: #'
427+
+ [...failedPRs].join(', #'))
428+
}

0 commit comments

Comments
 (0)