From 594b9b0d1e3fe773a14b9230f92f5a40ede5f403 Mon Sep 17 00:00:00 2001 From: ethanrubio Date: Wed, 24 May 2017 10:07:25 -0700 Subject: [PATCH] Add CircleCI --- ci-services/circleci.js | 33 +++++++++++++++++++++++++++++++++ ci-services/tests.js | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 ci-services/circleci.js diff --git a/ci-services/circleci.js b/ci-services/circleci.js new file mode 100644 index 00000000..a8918334 --- /dev/null +++ b/ci-services/circleci.js @@ -0,0 +1,33 @@ +const env = process.env +const _ = require("lodash") +const exec = require("child_process").execSync + +function getNumberOfCommitsOnBranch() { + const grepAgument = `refs/heads/${env.CIRCLE_BRANCH}` + const notArgument = `$(git for-each-ref --format="%(refname)" refs/heads/ | grep -v ${grepAgument})` + return _.toNumber( + exec( + `git log ${env.CIRCLE_BRANCH} --oneline --not ${notArgument} | wc -l` + ).toString() + ) +} + +function getCommitMessage() { + return exec('git log --format="%s" -n1 $CIRCLE_SHA1').toString() +} + +module.exports = { + // The GitHub repo slug + repoSlug: `${env.CIRCLE_PROJECT_USERNAME}/${env.CIRCLE_PROJECT_REPONAME}`, + // The name of the current branch + branchName: env.CIRCLE_BRANCH, + // The commit message of the last commit on the current branch + commitMessage: getCommitMessage(), + // Is this the first push on this branch + // i.e. the Greenkeeper commit + firstPush: getNumberOfCommitsOnBranch() === 1, + // Is this a regular build + correctBuild: _.isEmpty(env.CI_PULL_REQUEST), + // Should the lockfile be uploaded from this build + uploadBuild: env.CIRCLE_NODE_INDEX === "0" +} diff --git a/ci-services/tests.js b/ci-services/tests.js index 9c99c674..99920892 100644 --- a/ci-services/tests.js +++ b/ci-services/tests.js @@ -1,5 +1,6 @@ const env = process.env module.exports = { - travis: () => env.TRAVIS === 'true' + travis: () => env.TRAVIS === 'true', + circleci: () => env.CIRCLECI === 'true' }