Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add team city support #131

Merged
merged 1 commit into from
Apr 4, 2018
Merged
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
35 changes: 35 additions & 0 deletions ci-services/teamcity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const gitHelpers = require('../lib/git-helpers')

const env = process.env

/**
* In order for this to work with Team City, the build configuration needs to set
* the following environment variables:
*
* - VCS_ROOT_URL from the vcsroot.<vcsrootid>.url parameter
* - VCS_ROOT_BRANCH from the teamcity.build.branch parameter
*/

/**
* Is the current branch a pull request
*/
function isPullRequest () {
return /.+\/merge|head/.test(env.VCS_ROOT_BRANCH)
}

/**
* Should the lockfile be uploaded
*/
function shouldUpload () {
const re = /^(chore|fix)\(package\): update lockfile|([^ ]+ to version).*$/mi
const lastCommitMessage = gitHelpers.getLastCommitMessage()
return re.test(lastCommitMessage)
}

module.exports = {
repoSlug: gitHelpers.getRepoSlug(env.VCS_ROOT_URL),
branchName: env.VCS_ROOT_BRANCH,
firstPush: shouldUpload(),
correctBuild: !isPullRequest(),
uploadBuild: shouldUpload()
}
3 changes: 2 additions & 1 deletion ci-services/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ module.exports = {
wercker: () => env.WERCKER === 'true',
codeship: () => env.CI_NAME === 'codeship',
bitrise: () => env.CI === 'true' && env.BITRISE_BUILD_NUMBER !== undefined,
semaphoreci: () => env.SEMAPHORE === 'true'
semaphoreci: () => env.SEMAPHORE === 'true',
teamcity: () => env.TEAMCITY_VERSION !== undefined
}
3 changes: 3 additions & 0 deletions lib/git-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module.exports = {
).toString()
)
},
getLastCommitMessage: function getLastCommitMessage () {
return exec('git log --format=%B -1').toString()
},
getRepoSlug: function getRepoSlug (githubUrl) {
var ghRegex = /\S+[:|/](\w+(?:[-]\w+)*)\/(\w+(?:[-]\w+)*)/g
var parsed = ghRegex.exec(githubUrl)
Expand Down