Skip to content

Commit 727e7fe

Browse files
authored
fix: Remove duplicated job from check-run (#20)
1 parent 1517bce commit 727e7fe

File tree

5 files changed

+59
-24
lines changed

5 files changed

+59
-24
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"runtimeExecutable": "node",
1111
"env": {
1212
"GITHUB_JOB": "build-and-test",
13-
"GITHUB_RUN_ID": "14889189674",
13+
"GITHUB_RUN_ID": "14931757054",
1414
"GITHUB_EVENT_PATH": "${workspaceFolder}/.vscode/mock-event.json",
15-
"GITHUB_REPOSITORY": "DataDog/ensure-ci-success",
15+
"GITHUB_REPOSITORY": "DataDog/system-tests",
1616
"GITHUB_EVENT_NAME": "pull_request",
1717
"GITHUB_REF": "refs/pull/123/merge",
1818
"INPUT-INITIAL-DELAY-SECONDS": "1",

.vscode/mock-event.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"pull_request": {
33
"head": {
4-
"sha": "b2801e7303a63bf353431b91960eef449d4c5c62"
4+
"sha": "06b38da42a718808cc59f75a086c89e931a088ad"
55
}
66
}
77
}

dist/index.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116359,34 +116359,51 @@ class CheckReport {
116359116359
ref: this.sha,
116360116360
per_page: 100,
116361116361
});
116362-
const checkRuns = [];
116362+
const checkRuns = {};
116363116363
for (const suite of checkSuites) {
116364116364
if (suite.latest_check_runs_count === 0) {
116365116365
coreExports.debug(`Check suite ${suite.id} has no check runs (${suite.url}`);
116366116366
}
116367-
else if (suite.conclusion !== null &&
116368-
['success', 'neutral', 'skipped'].includes(suite.conclusion)) {
116369-
coreExports.info(`Check suite ${suite.id} conclusion is ${suite.conclusion} (${suite.latest_check_runs_count} runs) (${suite.url})`);
116370-
}
116371116367
else {
116372-
coreExports.info(`Get ${suite.latest_check_runs_count} runs for check suite ${suite.url}`);
116368+
// we cannot skip any suite, because rerun may have been triggered
116369+
coreExports.info(`Get ${suite.latest_check_runs_count} runs for check suite ${suite.url} (conclusion: ${suite.conclusion})`);
116373116370
const subCheckRuns = await octokit.paginate(octokit.rest.checks.listForSuite, {
116374116371
owner: this.owner,
116375116372
repo: this.repo,
116376116373
check_suite_id: suite.id,
116377116374
per_page: 100,
116378116375
});
116379-
checkRuns.push(...subCheckRuns);
116376+
subCheckRuns.forEach(checkRun => {
116377+
// dark corners of github API: there is no way to get "last check run" for a ref
116378+
// so we filter out them by app.id/names
116379+
if (checkRun.name.includes('${{')) {
116380+
// dark dark corners of github API: names can be not fully interpreted
116381+
// ignoring them
116382+
coreExports.debug(`Skipping GitHub Actions check run ${checkRun.html_url}`);
116383+
return;
116384+
}
116385+
const key = `${checkRun.app?.id}#${checkRun.name}`;
116386+
if (key in checkRuns) {
116387+
coreExports.debug(`Duplicate check run ${checkRun.html_url}`);
116388+
if (checkRun.id > checkRuns[key].id) {
116389+
// pick the last one
116390+
checkRuns[key] = checkRun;
116391+
}
116392+
}
116393+
else {
116394+
checkRuns[key] = checkRun;
116395+
}
116396+
});
116380116397
}
116381116398
}
116382-
coreExports.info(`Found ${checkRuns.length} check runs`);
116399+
coreExports.info(`Found ${Object.keys(checkRuns).length} check runs`);
116383116400
const statuses = await getAllCombinedStatuses(octokit, {
116384116401
owner: this.owner,
116385116402
repo: this.repo,
116386116403
ref: this.sha,
116387116404
});
116388116405
coreExports.info(`Found ${statuses.length} commit statuses`);
116389-
for (const check of checkRuns) {
116406+
for (const check of Object.values(checkRuns)) {
116390116407
this.items.push(SummaryRow.fromCheck(check, this.ignoredNameRegexps, this.currentJobName));
116391116408
}
116392116409
for (const status of statuses) {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/check-report.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,31 +85,49 @@ export class CheckReport {
8585
per_page: 100,
8686
});
8787

88-
const checkRuns: CheckRunType[] = [];
88+
const checkRuns: Record<string, CheckRunType> = {};
8989

9090
for (const suite of checkSuites) {
9191
if (suite.latest_check_runs_count === 0) {
9292
core.debug(`Check suite ${suite.id} has no check runs (${suite.url}`);
93-
} else if (
94-
suite.conclusion !== null &&
95-
['success', 'neutral', 'skipped'].includes(suite.conclusion)
96-
) {
93+
} else {
94+
// we cannot skip any suite, because rerun may have been triggered
9795
core.info(
98-
`Check suite ${suite.id} conclusion is ${suite.conclusion} (${suite.latest_check_runs_count} runs) (${suite.url})`
96+
`Get ${suite.latest_check_runs_count} runs for check suite ${suite.url} (conclusion: ${suite.conclusion})`
9997
);
100-
} else {
101-
core.info(`Get ${suite.latest_check_runs_count} runs for check suite ${suite.url}`);
10298
const subCheckRuns = await octokit.paginate(octokit.rest.checks.listForSuite, {
10399
owner: this.owner,
104100
repo: this.repo,
105101
check_suite_id: suite.id,
106102
per_page: 100,
107103
});
108-
checkRuns.push(...subCheckRuns);
104+
subCheckRuns.forEach(checkRun => {
105+
// dark corners of github API: there is no way to get "last check run" for a ref
106+
// so we filter out them by app.id/names
107+
108+
if (checkRun.name.includes('${{')) {
109+
// dark dark corners of github API: names can be not fully interpreted
110+
// ignoring them
111+
core.debug(`Skipping GitHub Actions check run ${checkRun.html_url}`);
112+
return;
113+
}
114+
115+
const key = `${checkRun.app?.id}#${checkRun.name}`;
116+
117+
if (key in checkRuns) {
118+
core.debug(`Duplicate check run ${checkRun.html_url}`);
119+
if (checkRun.id > checkRuns[key].id) {
120+
// pick the last one
121+
checkRuns[key] = checkRun;
122+
}
123+
} else {
124+
checkRuns[key] = checkRun;
125+
}
126+
});
109127
}
110128
}
111129

112-
core.info(`Found ${checkRuns.length} check runs`);
130+
core.info(`Found ${Object.keys(checkRuns).length} check runs`);
113131

114132
const statuses = await getAllCombinedStatuses(octokit, {
115133
owner: this.owner,
@@ -118,7 +136,7 @@ export class CheckReport {
118136
});
119137
core.info(`Found ${statuses.length} commit statuses`);
120138

121-
for (const check of checkRuns) {
139+
for (const check of Object.values(checkRuns)) {
122140
this.items.push(SummaryRow.fromCheck(check, this.ignoredNameRegexps, this.currentJobName));
123141
}
124142

0 commit comments

Comments
 (0)