Skip to content

Commit 9d2e214

Browse files
committed
feat: check Actions and handle doc-only changes
Doc-only changes don't need a full Jenkins CI, instead we can check if the last Actions run was successful. Therefore this commit also adds check for Action runs. Jenkins CI messages were improved as well. Fix: nodejs#324 Ref: nodejs/node#32335
1 parent 5730faf commit 9d2e214

File tree

5 files changed

+114
-12
lines changed

5 files changed

+114
-12
lines changed

lib/ci/ci_type_parser.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ const CI_TYPE_ENUM = {
2626

2727
const CI_PROVIDERS = {
2828
JENKINS: 'jenkins',
29-
GITHUB: 'github-check'
29+
GITHUB: 'github-check',
30+
NODEJS: 'nodejs'
3031
};
3132

3233
const { JOB_CI, FULL_CI } = CI_TYPE_ENUM;

lib/pr_checker.js

+77-4
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class PRChecker {
204204
}
205205

206206
async checkCI() {
207-
const ciType = this.argv.ciType || CI_PROVIDERS.JENKINS;
207+
const ciType = this.argv.ciType || CI_PROVIDERS.NODEJS;
208208
const providers = Object.values(CI_PROVIDERS);
209209

210210
if (!providers.includes(ciType)) {
@@ -218,6 +218,8 @@ class PRChecker {
218218
status = await this.checkJenkinsCI();
219219
} else if (ciType === CI_PROVIDERS.GITHUB) {
220220
status = this.checkGitHubCI();
221+
} else if (ciType === CI_PROVIDERS.NODEJS) {
222+
status &= await this.checkNodejsCI();
221223
}
222224

223225
return status;
@@ -233,7 +235,7 @@ class PRChecker {
233235

234236
let status = true;
235237
if (!ciMap.size) {
236-
cli.error('No CI runs detected');
238+
cli.error('No Jenkins CI runs detected');
237239
this.CIStatus = false;
238240
return false;
239241
} else if (!this.hasFullCI(ciMap)) {
@@ -292,17 +294,61 @@ class PRChecker {
292294
cli.error(
293295
`${failures.length} failure(s) on the last Jenkins CI run`);
294296
status = false;
297+
// NOTE(mmarchini): not sure why PEDING returns null
298+
} else if (result === null) {
299+
cli.error(
300+
'Last Jenkins CI still running');
301+
status = false;
302+
} else {
303+
cli.ok('Last Jenkins CI successful');
295304
}
296305
}
297306

298307
this.CIStatus = status;
299308
return status;
300309
}
301310

311+
checkActionsCI() {
312+
const { cli, commits } = this;
313+
314+
if (!commits || commits.length === 0) {
315+
cli.error('No commits detected');
316+
return false;
317+
}
318+
319+
// NOTE(mmarchini): we only care about the last commit. Maybe in the future
320+
// we'll want to check all commits for a successful CI.
321+
const { commit } = commits[commits.length - 1];
322+
323+
this.CIStatus = false;
324+
const checkSuites = commit.checkSuites || { nodes: [] };
325+
if (!commit.status && checkSuites.nodes.length === 0) {
326+
cli.error('No GitHub CI runs detected');
327+
return false;
328+
}
329+
330+
// GitHub new Check API
331+
for (const { status, conclusion } of checkSuites.nodes) {
332+
if (status !== 'COMPLETED') {
333+
cli.error('GitHub CI is still running');
334+
return false;
335+
}
336+
337+
if (!['SUCCESS', 'NEUTRAL'].includes(conclusion)) {
338+
cli.error('Last GitHub CI failed');
339+
return false;
340+
}
341+
}
342+
343+
cli.ok('Last GitHub Actions successful');
344+
this.CIStatus = true;
345+
return true;
346+
}
347+
302348
checkGitHubCI() {
303349
const { cli, commits } = this;
304350

305-
if (!commits) {
351+
if (!commits || commits.length === 0) {
306352
cli.error('No commits detected');
307353
return false;
308354
}
@@ -314,7 +360,7 @@ class PRChecker {
314360
this.CIStatus = false;
315361
const checkSuites = commit.checkSuites || { nodes: [] };
316362
if (!commit.status && checkSuites.nodes.length === 0) {
317-
cli.error('No CI runs detected');
363+
cli.error('No GitHub CI runs detected');
318364
return false;
319365
}
320366

@@ -350,6 +396,33 @@ class PRChecker {
350396
return true;
351397
}
352398

399+
isOnlyDocChanges() {
400+
const { cli, pr } = this;
401+
402+
// NOTE(mmarchini): if files not present, fallback
403+
// to old behavior. This should only be the case on old tests
404+
// TODO(mmarchini): add files to all fixtures on old tests
405+
if (!pr.files) {
406+
return false;
407+
}
408+
409+
for (const { path } of pr.files.nodes) {
410+
if (!path.endsWith('.md')) {
411+
return false;
412+
}
413+
}
414+
cli.info('Doc-only changes');
415+
return true;
416+
}
417+
418+
async checkNodejsCI() {
419+
let status = this.checkActionsCI();
420+
if (!this.isOnlyDocChanges()) {
421+
status &= await this.checkJenkinsCI();
422+
}
423+
return status;
424+
}
425+
353426
checkAuthor() {
354427
const { cli, commits, pr } = this;
355428

lib/queries/PR.gql

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ query PR($prid: Int!, $owner: String!, $repo: String!) {
1818
name
1919
}
2020
},
21+
files(first: 100) {
22+
nodes {
23+
path
24+
}
25+
},
2126
title,
2227
baseRefName,
2328
headRefName,

lib/session.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class Session {
9999
}
100100

101101
get ciType() {
102-
return this.config.ciType || 'jenkins';
102+
return this.config.ciType || 'nodejs';
103103
}
104104

105105
get pullName() {

test/unit/pr_checker.test.js

+29-6
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ describe('PRChecker', () => {
619619

620620
const expectedLogs = {
621621
error: [
622-
['No CI runs detected']
622+
['No GitHub CI runs detected'],
623+
['No Jenkins CI runs detected']
623624
]
624625
};
625626

@@ -646,6 +647,12 @@ describe('PRChecker', () => {
646647
const cli = new TestCLI();
647648

648649
const expectedLogs = {
650+
ok: [
651+
['Last Jenkins CI successful']
652+
],
653+
error: [
654+
['No commits detected']
655+
],
649656
info: [
650657
[
651658
'Last Full PR CI on 2017-10-25T04:16:36.458Z: ' +
@@ -693,7 +700,7 @@ describe('PRChecker', () => {
693700
const checker = new PRChecker(cli, data, {}, argv);
694701

695702
const status = await checker.checkCI();
696-
assert(status);
703+
assert(!status);
697704
cli.assertCalledWith(expectedLogs, {
698705
ignore: ['startSpinner', 'updateSpinner', 'stopSpinner']
699706
});
@@ -712,6 +719,12 @@ describe('PRChecker', () => {
712719
],
713720
info: [
714721
['Last Full PR CI on 2017-10-24T11:19:25Z: https://ci.nodejs.org/job/node-test-pull-request/10984/']
722+
],
723+
ok: [
724+
['Last Jenkins CI successful']
725+
],
726+
error: [
727+
['No GitHub CI runs detected']
715728
]
716729
};
717730

@@ -754,7 +767,12 @@ describe('PRChecker', () => {
754767
'https://ci.nodejs.org/job/node-test-pull-request/12984/'
755768
]
756769
],
757-
error: []
770+
ok: [
771+
['Last Jenkins CI successful']
772+
],
773+
error: [
774+
['No GitHub CI runs detected']
775+
]
758776
};
759777

760778
const checker = new PRChecker(cli, {
@@ -792,7 +810,12 @@ describe('PRChecker', () => {
792810
'https://ci.nodejs.org/job/node-test-pull-request/12984/'
793811
]
794812
],
795-
error: []
813+
ok: [
814+
['Last Jenkins CI successful']
815+
],
816+
error: [
817+
['No GitHub CI runs detected']
818+
]
796819
};
797820

798821
const checker = new PRChecker(cli, {
@@ -835,7 +858,7 @@ describe('PRChecker', () => {
835858

836859
const expectedLogs = {
837860
error: [
838-
['No CI runs detected']
861+
['No GitHub CI runs detected']
839862
]
840863
};
841864

@@ -1044,7 +1067,7 @@ describe('PRChecker', () => {
10441067

10451068
const expectedLogs = {
10461069
error: [
1047-
['No CI runs detected']
1070+
['No GitHub CI runs detected']
10481071
]
10491072
};
10501073

0 commit comments

Comments
 (0)