From d7320cc7547ac7afbae47779bc5ce9515c6f6997 Mon Sep 17 00:00:00 2001 From: Shovon Date: Fri, 26 Feb 2021 07:10:18 -0500 Subject: [PATCH] feat: update CI requirements for landing pull requests (#533) Refs: https://github.com/nodejs/node/pull/37308 --- lib/pr_checker.js | 38 +++++++++++++++++++++++-------- test/fixtures/first_timer_pr.json | 3 +++ test/unit/pr_checker.test.js | 6 ++--- test/unit/pr_summary.test.js | 2 +- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/pr_checker.js b/lib/pr_checker.js index 5aceb94..77e638e 100644 --- a/lib/pr_checker.js +++ b/lib/pr_checker.js @@ -397,8 +397,8 @@ class PRChecker { return true; } - isOnlyDocChanges() { - const { cli, pr } = this; + requiresJenkinsRun() { + const { pr } = this; // NOTE(mmarchini): if files not present, fallback // to old behavior. This should only be the case on old tests @@ -407,19 +407,37 @@ class PRChecker { return false; } - for (const { path } of pr.files.nodes) { - if (!path.endsWith('.md')) { - return false; - } - } - cli.info('Doc-only changes'); - return true; + const ciNeededFolderRx = /^(deps|lib|src|test)\//; + const ciNeededToolFolderRx = + /^tools\/(code_cache|gyp|icu|inspector|msvs|snapshot|v8_gypfiles)/; + const ciNeededFileRx = /^tools\/\.+.py$/; + const ciNeededFileList = [ + 'tools/build-addons.js', + 'configure', + 'configure.py', + 'Makefile' + ]; + const ciNeededExtensionList = ['.gyp', '.gypi', '.bat']; + + return pr.files.nodes.some( + ({ path }) => + ciNeededFolderRx.test(path) || + ciNeededToolFolderRx.test(path) || + ciNeededFileRx.test(path) || + ciNeededFileList.includes(path) || + ciNeededExtensionList.some((ext) => path.endsWith(ext)) + ); } async checkNodejsCI() { let status = this.checkActionsCI(); - if (!this.isOnlyDocChanges()) { + if ( + this.pr.labels.nodes.some((l) => l.name === 'needs-ci') || + this.requiresJenkinsRun() + ) { status &= await this.checkJenkinsCI(); + } else { + this.cli.info('Green GitHub Actions CI is sufficient'); } return status; } diff --git a/test/fixtures/first_timer_pr.json b/test/fixtures/first_timer_pr.json index 1fce648..8e57b7c 100644 --- a/test/fixtures/first_timer_pr.json +++ b/test/fixtures/first_timer_pr.json @@ -11,6 +11,9 @@ "bodyText": "Awesome changes", "labels": { "nodes": [ + { + "name": "needs-ci" + }, { "name": "test" }, diff --git a/test/unit/pr_checker.test.js b/test/unit/pr_checker.test.js index 134015a..2c91594 100644 --- a/test/unit/pr_checker.test.js +++ b/test/unit/pr_checker.test.js @@ -655,7 +655,7 @@ describe('PRChecker', () => { ['No GitHub CI runs detected'] ], info: [ - ['Doc-only changes'] + ['Green GitHub Actions CI is sufficient'] ] }; @@ -697,7 +697,7 @@ describe('PRChecker', () => { ['Last GitHub Actions successful'] ], info: [ - ['Doc-only changes'] + ['Green GitHub Actions CI is sufficient'] ] }; @@ -741,7 +741,7 @@ describe('PRChecker', () => { ['Last GitHub Actions successful'] ], info: [ - ['Doc-only changes'] + ['Green GitHub Actions CI is sufficient'] ] }; diff --git a/test/unit/pr_summary.test.js b/test/unit/pr_summary.test.js index 46d5e3c..0bdb4e4 100644 --- a/test/unit/pr_summary.test.js +++ b/test/unit/pr_summary.test.js @@ -44,7 +44,7 @@ describe('PRSummary', () => { 'Their Github Account email ' + ' (@pr_author, first-time contributor)'], ['Branch', 'pr_author:awesome-changes -> nodejs:master'], - ['Labels', 'test, doc'], + ['Labels', 'needs-ci, test, doc'], ['Commits', '6'], ['Committers', '3'] ]