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

Codeship CI Integration #72

Merged
merged 21 commits into from
Jan 19, 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
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 !== ''
}