|
| 1 | +/* eslint-disable max-len */ |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +const exec = require('child_process').execSync; |
| 5 | + |
| 6 | +const env = process.env; |
| 7 | + |
| 8 | +const info = { |
| 9 | + // The GitHub repo slug |
| 10 | + repoSlug: env.TRAVIS_REPO_SLUG, |
| 11 | + // The name of the current branch |
| 12 | + branchName: env.TRAVIS_BRANCH, |
| 13 | + // Is this the first push on this branch |
| 14 | + // i.e. the Greenkeeper commit |
| 15 | + firstPush: !env.TRAVIS_COMMIT_RANGE, |
| 16 | + // Is this a regular build |
| 17 | + correctBuild: env.TRAVIS_PULL_REQUEST === 'false', |
| 18 | + // Should the lockfile be uploaded from this build |
| 19 | + uploadBuild: |
| 20 | + env.TRAVIS_JOB_NUMBER && |
| 21 | + env.TRAVIS_JOB_NUMBER.endsWith(`.${env.BUILD_LEADER_ID || 1}`), |
| 22 | +}; |
| 23 | + |
| 24 | +function isGreenkeeperBranch() { |
| 25 | + if (!info.branchName) { |
| 26 | + console.error( |
| 27 | + 'No branch details set, so assuming not a Greenkeeper branch', |
| 28 | + ); |
| 29 | + return false; |
| 30 | + } |
| 31 | + |
| 32 | + if (!info.branchName.startsWith('greenkeeper')) { |
| 33 | + console.log(`${info.branchName} is not a greenkeeper branch`); |
| 34 | + return false; |
| 35 | + } |
| 36 | + |
| 37 | + return true; |
| 38 | +} |
| 39 | + |
| 40 | +function execCmd(cmd) { |
| 41 | + return exec(cmd, { stdio: [ |
| 42 | + process.stdin, |
| 43 | + process.stdout, |
| 44 | + process.stderr, |
| 45 | + ] }); |
| 46 | +} |
| 47 | +module.exports = function() { |
| 48 | + if (isGreenkeeperBranch()) { |
| 49 | + console.log('found greenkeeper branch build, use npm install'); |
| 50 | + return execCmd('npm install'); |
| 51 | + } |
| 52 | + console.log('running npm ci'); |
| 53 | + return execCmd('npm ci'); |
| 54 | +}; |
| 55 | + |
| 56 | +if (require.main === module) { |
| 57 | + module.exports(); |
| 58 | +} |
0 commit comments