Skip to content

Commit d5e53bb

Browse files
committed
fix(ci): ignore superseded GitHub Actions runs
A commit can have multiple check suites for the same workflow and event when a branch is force-pushed away from and then back to the same SHA. Select the suite with the highest workflow run number and request only the latest check runs to avoid reporting superseded CI failures. Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com>
1 parent 22b9f8f commit d5e53bb

14 files changed

Lines changed: 116 additions & 16 deletions

‎lib/pr_checker.js‎

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,30 @@ const FAST_TRACK_RE = /^Fast-track has been requested by @(.+?)\. Please 👍 to
2929
const FAST_TRACK_MIN_APPROVALS = 2;
3030
const GIT_CONFIG_GUIDE_URL = 'https://github.com/nodejs/node/blob/99b1ada/doc/guides/contributing/pull-requests.md#step-1-fork';
3131

32+
function getLatestGitHubActionsCheckSuites(checkSuites) {
33+
const latestByWorkflow = new Map();
34+
35+
for (const suite of checkSuites) {
36+
const { app, workflowRun } = suite;
37+
38+
if (app?.slug !== 'github-actions') {
39+
continue;
40+
}
41+
42+
// Runs triggered by different events are independent and must not
43+
// supersede one another.
44+
const key = `${workflowRun.workflow.id}:${workflowRun.event}`;
45+
const current = latestByWorkflow.get(key);
46+
47+
if (!current ||
48+
workflowRun.runNumber > current.workflowRun.runNumber) {
49+
latestByWorkflow.set(key, suite);
50+
}
51+
}
52+
53+
return [...latestByWorkflow.values()];
54+
}
55+
3256
export const PR_CHECK_REASON_CODES = Object.freeze({
3357
CANCELLED_GITHUB_CI: 'cancelled-github-ci',
3458
CLOSED: 'closed',
@@ -459,14 +483,9 @@ export default class PRChecker {
459483
const pendingJobs = [];
460484

461485
// GitHub new Check API
462-
for (const { status, conclusion, app, checkRuns } of checkSuites.nodes) {
463-
if (app.slug !== 'github-actions') {
464-
// Ignore all non-github check suites, such as Dependabot and Codecov.
465-
// They are expected to show up on PRs whose head branch is not on a
466-
// fork and never complete.
467-
continue;
468-
}
469-
486+
const latestCheckSuites =
487+
getLatestGitHubActionsCheckSuites(checkSuites.nodes);
488+
for (const { status, conclusion, app, checkRuns } of latestCheckSuites) {
470489
if (status !== 'COMPLETED') {
471490
pendingJobs.push({ app: app.slug, status, conclusion });
472491
continue;

‎lib/queries/PR.gql‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ query PR($prid: Int!, $owner: String!, $repo: String!) {
3636
}
3737
conclusion,
3838
status,
39-
checkRuns(first: 40) {
39+
workflowRun {
40+
event
41+
runNumber
42+
workflow {
43+
id
44+
}
45+
}
46+
checkRuns(first: 40, filterBy: { checkType: LATEST }) {
4047
nodes {
4148
name
4249
status

‎test/fixtures/github-ci/both-apis-failure.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"nodes": [
1515
{
1616
"app": { "slug": "github-actions" },
17+
"workflowRun": { "event": "pull_request", "runNumber": 1, "workflow": { "id": "workflow-1" } },
1718
"status": "COMPLETED",
1819
"conclusion": "FAILURE"
1920
}
@@ -22,4 +23,3 @@
2223
}
2324
}
2425
]
25-

‎test/fixtures/github-ci/both-apis-success.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"nodes": [
1515
{
1616
"app": { "slug": "github-actions" },
17+
"workflowRun": { "event": "pull_request", "runNumber": 1, "workflow": { "id": "workflow-1" } },
1718
"status": "COMPLETED",
1819
"conclusion": "SUCCESS"
1920
}
@@ -22,4 +23,3 @@
2223
}
2324
}
2425
]
25-

‎test/fixtures/github-ci/check-suite-cancelled.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"nodes": [
1212
{
1313
"app": { "slug": "github-actions" },
14+
"workflowRun": { "event": "pull_request", "runNumber": 1, "workflow": { "id": "workflow-1" } },
1415
"status": "COMPLETED",
1516
"conclusion": "CANCELLED",
1617
"checkRuns": {

‎test/fixtures/github-ci/check-suite-failure.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"nodes": [
1212
{
1313
"app": { "slug": "github-actions" },
14+
"workflowRun": { "event": "pull_request", "runNumber": 1, "workflow": { "id": "workflow-1" } },
1415
"status": "COMPLETED",
1516
"conclusion": "FAILURE",
1617
"checkRuns": {

‎test/fixtures/github-ci/check-suite-pending.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
"nodes": [
1212
{
1313
"app": { "slug": "github-actions" },
14+
"workflowRun": { "event": "pull_request", "runNumber": 1, "workflow": { "id": "workflow-1" } },
1415
"status": "IN_PROGRESS"
1516
}
1617
]
1718
}
1819
}
1920
}
2021
]
21-

‎test/fixtures/github-ci/check-suite-skipped.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"nodes": [
1212
{
1313
"app": { "slug": "github-actions" },
14+
"workflowRun": { "event": "pull_request", "runNumber": 1, "workflow": { "id": "workflow-1" } },
1415
"status": "COMPLETED",
1516
"conclusion": "SKIPPED"
1617
}

‎test/fixtures/github-ci/check-suite-success.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"nodes": [
1212
{
1313
"app": { "slug": "github-actions" },
14+
"workflowRun": { "event": "pull_request", "runNumber": 1, "workflow": { "id": "workflow-1" } },
1415
"status": "COMPLETED",
1516
"conclusion": "SUCCESS"
1617
}

‎test/fixtures/github-ci/status-failure-check-suite-succeed.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"nodes": [
1515
{
1616
"app": { "slug": "github-actions" },
17+
"workflowRun": { "event": "pull_request", "runNumber": 1, "workflow": { "id": "workflow-1" } },
1718
"status": "COMPLETED",
1819
"conclusion": "SUCCESS"
1920
}
@@ -22,4 +23,3 @@
2223
}
2324
}
2425
]
25-

0 commit comments

Comments
 (0)