-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtravis-install.js
58 lines (50 loc) · 1.34 KB
/
travis-install.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
/* eslint-disable max-len */
'use strict';
const exec = require('child_process').execSync;
const env = process.env;
const info = {
// The GitHub repo slug
repoSlug: env.TRAVIS_REPO_SLUG,
// The name of the current branch
branchName: env.TRAVIS_BRANCH,
// Is this the first push on this branch
// i.e. the Greenkeeper commit
firstPush: !env.TRAVIS_COMMIT_RANGE,
// Is this a regular build
correctBuild: env.TRAVIS_PULL_REQUEST === 'false',
// Should the lockfile be uploaded from this build
uploadBuild:
env.TRAVIS_JOB_NUMBER &&
env.TRAVIS_JOB_NUMBER.endsWith(`.${env.BUILD_LEADER_ID || 1}`),
};
function isGreenkeeperBranch() {
if (!info.branchName) {
console.error(
'No branch details set, so assuming not a Greenkeeper branch',
);
return false;
}
if (!info.branchName.startsWith('greenkeeper')) {
console.log(`${info.branchName} is not a greenkeeper branch`);
return false;
}
return true;
}
function execCmd(cmd) {
return exec(cmd, { stdio: [
process.stdin,
process.stdout,
process.stderr,
] });
}
module.exports = function() {
if (isGreenkeeperBranch()) {
console.log('found greenkeeper branch build, use npm install');
return execCmd('npm install');
}
console.log('running npm ci');
return execCmd('npm ci');
};
if (require.main === module) {
module.exports();
}