Skip to content

Commit

Permalink
Add CircleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanrubio committed May 24, 2017
1 parent c72a5a5 commit 594b9b0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 33 additions & 0 deletions ci-services/circleci.js
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 2 additions & 1 deletion ci-services/tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const env = process.env

module.exports = {
travis: () => env.TRAVIS === 'true'
travis: () => env.TRAVIS === 'true',
circleci: () => env.CIRCLECI === 'true'
}

0 comments on commit 594b9b0

Please sign in to comment.