Skip to content

Commit

Permalink
feat: add team city support
Browse files Browse the repository at this point in the history
  • Loading branch information
tagoro9 authored and janl committed Apr 4, 2018
1 parent a075053 commit 6a1068a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
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

0 comments on commit 6a1068a

Please sign in to comment.