Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add CircleCI #18

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
}