Skip to content

Commit

Permalink
feat: add basic Codeship CI Integration
Browse files Browse the repository at this point in the history
* basic codeship support
  • Loading branch information
selbyk authored and Realtin committed Jan 19, 2018
1 parent b290b64 commit 258e9c0
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
95 changes: 95 additions & 0 deletions ci-services/codeship.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const relative = require('require-relative')
const gitHelpers = require('../lib/git-helpers')

const env = process.env
const pkg = relative('./package.json')

/**
* Generates repoSlug from user set `GH_ORG` env var and Codeship set
* `CI_REPO_NAME`. Fails back to extracting from `package.json`.repository.url
*/
function getRepoSlug () {
if (env.GH_ORG) {
return `${env.GH_ORG}/${env.CI_REPO_NAME}`
}
let re = /github\.com[:/]([^/]+\/[^/\.]+)/g // eslint-disable-line no-useless-escape
let result
if (typeof pkg.repository === 'string') {
result = re.exec(pkg.repository)
} else if (typeof pkg.repository.url === 'string') {
result = re.exec(pkg.repository.url)
}
if (result && result[1]) {
return result[1]
}
console.warn('Failed to extract repoSlug from package.json, pushes will probably fail.')
console.warn('Set repository.url with the repo GitHub url in package.json.')
return env.CI_REPO_NAME
}

/**
* Should update the `package-lock.json`
*/
function shouldUpdate () {
let re = /^(chore|fix)\(package\): update [^ ]+ to version.*$/mi
return re.test(env.CI_COMMIT_MESSAGE)
}

module.exports = {
// The GitHub repo slug
repoSlug: getRepoSlug(),
// The name of the current branch
branchName: env.CI_BRANCH,
// Is this the first push on this branch
// i.e. the Greenkeeper commit
firstPush: shouldUpdate(),
// Is this a regular build (use tag: ^greenkeeper/)
correctBuild: shouldUpdate(),
// Should the lockfile be uploaded from this build (use tag: ^greenkeeper/)
uploadBuild: shouldUpdate(),
commitNum: gitHelpers.getNumberOfCommitsOnBranch(env.CI_BRANCH),
realFirstPush: gitHelpers.getNumberOfCommitsOnBranch(env.CI_BRANCH) === 1
}

/*
Example `codeship-steps.yml`:
```yml
- name: "Greenkeeper: install greenkeeper-lockfile"
tag: ^greenkeeper/
service: app
command: npm i -g greenkeeper-lockfile
- name: "Greenkeeper: update lockfile"
tag: ^greenkeeper/
service: app
command: greenkeeper-lockfile-update
- name: Test
service: app
command: npm run codeship-test
- name: "Greenkeeper: pushing lockfile"
tag: ^greenkeeper/
service: app
command: greenkeeper-lockfile-upload
```
`repository` key in `package.json` or GH_ORG with the org name is required, as there's no way to
get it from the ENV vars that Codeship sets.
`package.json`:
```
{
...
"repository": "https://github.com/org/repo.git"
},
...
}
```
```
{
...
"repository": {
"type": "git",
"url": "https://github.com/org/repo.git"
},
...
}
```
*/
1 change: 1 addition & 0 deletions ci-services/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
jenkins: () => env.JENKINS_URL !== undefined,
travis: () => env.TRAVIS === 'true',
wercker: () => env.WERCKER === 'true',
codeship: () => env.CI_NAME === 'codeship',
bitrise: () => env.CI === 'true' && env.BITRISE_BUILD_NUMBER !== ''
}

0 comments on commit 258e9c0

Please sign in to comment.