-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
pr-check.js
128 lines (108 loc) · 3.23 KB
/
pr-check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* Copyright 2018 The AMP HTML Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';
const argv = require('minimist')(process.argv.slice(2));
const {
printChangeSummary,
startTimer,
stopTimer,
stopTimedJob,
timedExec,
} = require('../pr-check/utils');
const {determineBuildTargets} = require('../pr-check/build-targets');
const {runYarnChecks} = require('../pr-check/yarn-checks');
const FILENAME = 'pr-check.js';
/**
* This file runs tests against the local workspace to mimic the CI build as
* closely as possible.
* @param {Function} cb
*/
async function prCheck(cb) {
const failTask = () => {
stopTimer(FILENAME, FILENAME, startTime);
const err = new Error('Local PR check failed. See logs above.');
err.showStack = false;
cb(err);
};
const runCheck = cmd => {
const {status} = timedExec(cmd, FILENAME);
if (status != 0) {
failTask();
}
};
const startTime = startTimer(FILENAME, FILENAME);
if (!runYarnChecks(FILENAME)) {
stopTimedJob(FILENAME, startTime);
return;
}
printChangeSummary(FILENAME);
const buildTargets = determineBuildTargets(FILENAME);
runCheck('gulp lint --local_changes');
runCheck('gulp prettify --local_changes');
runCheck('gulp presubmit');
runCheck('gulp check-exact-versions');
if (buildTargets.has('AVA')) {
runCheck('gulp ava');
}
if (buildTargets.has('BABEL_PLUGIN')) {
runCheck('gulp babel-plugin-tests');
}
if (buildTargets.has('CACHES_JSON')) {
runCheck('gulp caches-json');
}
if (buildTargets.has('DOCS')) {
runCheck('gulp check-links');
}
if (buildTargets.has('DEV_DASHBOARD')) {
runCheck('gulp dev-dashboard-tests');
}
if (buildTargets.has('OWNERS')) {
runCheck('gulp check-owners');
}
if (buildTargets.has('RUNTIME')) {
runCheck('gulp dep-check');
runCheck('gulp check-types');
}
if (buildTargets.has('RUNTIME') || buildTargets.has('UNIT_TEST')) {
runCheck('gulp unit --local_changes --headless');
}
if (
buildTargets.has('RUNTIME') ||
buildTargets.has('FLAG_CONFIG') ||
buildTargets.has('INTEGRATION_TEST')
) {
if (!argv.nobuild) {
runCheck('gulp clean');
runCheck('gulp dist --fortesting');
}
runCheck('gulp integration --nobuild --compiled --headless');
}
if (buildTargets.has('RUNTIME') || buildTargets.has('VALIDATOR')) {
runCheck('gulp validator');
}
if (buildTargets.has('VALIDATOR_WEBUI')) {
runCheck('gulp validator-webui');
}
stopTimer(FILENAME, FILENAME, startTime);
}
module.exports = {
prCheck,
};
prCheck.description =
'Runs a subset of the Travis CI checks against local changes.';
prCheck.flags = {
'nobuild': ' Skips building the runtime via `gulp dist`.',
};