Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
greenkeeper lockfile install with npm ci
language: node_js
node_js:
- '8'
- '10'
before_install:
- if [[ `npm -v` != 6* ]]; then npm install -g npm@6; fi
- npm install -g greenkeeper-lockfile
install:
- node travis-install.js
before_script: greenkeeper-lockfile-update
after_script: greenkeeper-lockfile-upload
cache:
directories:
- "$HOME/.npm"
notifications:
webhooks: https://www.travisbuddy.com/
sudo: false
/* 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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.