Skip to content

Commit a348d7f

Browse files
committed
feat: support Buddy CI
1 parent 87b6931 commit a348d7f

File tree

6 files changed

+104
-20
lines changed

6 files changed

+104
-20
lines changed

README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,27 @@ if (isCI) {
5454

5555
## Supported CI
5656

57-
| CI Service (`name`) | `service` | `isCi` | `commit` | `build` | `buildUrl` | `branch` | `job` | `jobUrl` | `pr` | `isPr` | `slug` | `root` |
58-
|-----------------------------------------------------------------------------------------------------------|:-----------:|:------:|:--------:|:-------:|:----------:|:--------:|:-----:|:--------:|:----:|:------:|:------:|:------:|
59-
| [AppVeyor]( https://www.appveyor.com/docs/environment-variables) | `appveyor` ||||||||||||
60-
| [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html) | `bamboo` ||||||||||||
61-
| [Bitbucket](https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html) | `bitbucket` ||||||||||||
62-
| [Bitrise](http://devcenter.bitrise.io/faq/available-environment-variables/#exposed-by-bitriseio) | `bitrise` ||||||||||||
63-
| [Buildkite](https://buildkite.com/docs/builds/environment-variables) | `buildkite` ||||||||||||
64-
| [CircleCI](https://circleci.com/docs/1.0/environment-variables) | `circleci` ||||||||||||
65-
| [Cirrus CI](https://cirrus-ci.org/guide/writing-tasks/#environment-variables) | `cirrus` ||||||||||||
66-
| [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html) | `codebuild` ||||||||||||
67-
| [Codeship](https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables) | `codeship` ||||||||||||
68-
| [Drone](http://readme.drone.io/0.5/usage/environment-reference) | `drone` ||||||||||||
69-
| [Gitlab CI/CD](https://docs.gitlab.com/ce/ci/variables/README.html) | `gitlab` ||||||||||||
70-
| [Jenkins](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project) | `jenkins` ||||||||||||
71-
| [Semaphore](https://semaphoreci.com/docs/available-environment-variables.html) | `semaphore` ||||||||||||
72-
| [Shippable](http://docs.shippable.com/ci/env-vars/#stdEnv) | `shippable` ||||||||||||
73-
| [TeamCity](https://confluence.jetbrains.com/display/TCD10/Predefined+Build+Parameters) | `teamcity` ||||||||||||
74-
| [Travis CI](https://docs.travis-ci.com/user/environment-variables) | `travis` ||||||||||||
75-
| [Visual Studio Team Services](https://docs.microsoft.com/en-us/vsts/pipelines/build/variables) | `vsts` ||||||||||||
76-
| [Wercker](http://devcenter.wercker.com/docs/environment-variables/available-env-vars#hs_cos_wrapper_name) | `wercker` ||||||||||||
57+
| CI Service (`name`) | `service` | `isCi` | `commit` | `build` | `buildUrl` | `branch` | `job` | `jobUrl` | `pr` | `isPr` | `slug` | `root` |
58+
|----------------------------------------------------------------------------------------------------------------|:-----------:|:------:|:--------:|:-------:|:----------:|:--------:|:-----:|:--------:|:----:|:------:|:------:|:------:|
59+
| [AppVeyor]( https://www.appveyor.com/docs/environment-variables) | `appveyor` ||||||||||||
60+
| [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html) | `bamboo` ||||||||||||
61+
| [Bitbucket](https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html) | `bitbucket` ||||||||||||
62+
| [Bitrise](http://devcenter.bitrise.io/faq/available-environment-variables/#exposed-by-bitriseio) | `bitrise` ||||||||||||
63+
| [Buddy](https://buddy.works/knowledge/deployments/how-use-environment-variables#default-environment-variables) | `buddy` ||||||||||||
64+
| [Buildkite](https://buildkite.com/docs/builds/environment-variables) | `buildkite` ||||||||||||
65+
| [CircleCI](https://circleci.com/docs/1.0/environment-variables) | `circleci` ||||||||||||
66+
| [Cirrus CI](https://cirrus-ci.org/guide/writing-tasks/#environment-variables) | `cirrus` ||||||||||||
67+
| [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html) | `codebuild` ||||||||||||
68+
| [Codeship](https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables) | `codeship` ||||||||||||
69+
| [Drone](http://readme.drone.io/0.5/usage/environment-reference) | `drone` ||||||||||||
70+
| [Gitlab CI/CD](https://docs.gitlab.com/ce/ci/variables/README.html) | `gitlab` ||||||||||||
71+
| [Jenkins](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project) | `jenkins` ||||||||||||
72+
| [Semaphore](https://semaphoreci.com/docs/available-environment-variables.html) | `semaphore` ||||||||||||
73+
| [Shippable](http://docs.shippable.com/ci/env-vars/#stdEnv) | `shippable` ||||||||||||
74+
| [TeamCity](https://confluence.jetbrains.com/display/TCD10/Predefined+Build+Parameters) | `teamcity` ||||||||||||
75+
| [Travis CI](https://docs.travis-ci.com/user/environment-variables) | `travis` ||||||||||||
76+
| [Visual Studio Team Services](https://docs.microsoft.com/en-us/vsts/pipelines/build/variables) | `vsts` ||||||||||||
77+
| [Wercker](http://devcenter.wercker.com/docs/environment-variables/available-env-vars#hs_cos_wrapper_name) | `wercker` ||||||||||||
7778

7879
If none of the above CI services is detected, `commit` and `branch` are determined based on the local Git repository, and `isCi` is determined based on the `CI` environment variable.
7980

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const services = {
77
bamboo: require('./lib/bamboo'),
88
bitbucket: require('./lib/bitbucket'),
99
bitrise: require('./lib/bitrise'),
10+
buddy: require('./lib/buddy'),
1011
buildkite: require('./lib/buildkite'),
1112
circleci: require('./lib/circleci'),
1213
cirrus: require('./lib/cirrus'),

lib/buddy.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// https://buddy.works/knowledge/deployments/how-use-environment-variables#default-environment-variables
2+
3+
module.exports = {
4+
detect() {
5+
return Boolean(process.env.BUDDY_WORKSPACE_ID);
6+
},
7+
configuration() {
8+
return {
9+
name: 'Buddy',
10+
service: 'buddy',
11+
commit: process.env.BUDDY_EXECUTION_REVISION,
12+
build: process.env.BUDDY_EXECUTION_ID,
13+
buildUrl: process.env.BUDDY_EXECUTION_URL,
14+
branch: process.env.BUDDY_EXECUTION_BRANCH,
15+
pr: process.env.BUDDY_EXECUTION_PULL_REQUEST_ID,
16+
isPr: Boolean(
17+
process.env.BUDDY_EXECUTION_PULL_REQUEST_ID && process.env.BUDDY_EXECUTION_PULL_REQUEST_ID !== 'false'
18+
),
19+
slug: process.env.BUDDY_REPO_SLUG,
20+
};
21+
},
22+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"bamboo",
3333
"bitbucket",
3434
"bitrise",
35+
"buddy",
3536
"buildkite",
3637
"ci",
3738
"circle",

test/buddy.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import test from 'ava';
2+
import appveyor from '../lib/buddy';
3+
4+
test('Push', t => {
5+
process.env.BUDDY_WORKSPACE_ID = '111';
6+
process.env.BUDDY_EXECUTION_ID = '5';
7+
process.env.BUDDY_EXECUTION_URL =
8+
'https://app.buddy.works/pierredenisvanduynslager/playground/pipelines/pipeline/1111/execution/5b92a93863115e06fe4f7129';
9+
process.env.BUDDY_EXECUTION_REVISION = '5678';
10+
process.env.BUDDY_EXECUTION_BRANCH = 'master';
11+
process.env.BUDDY_REPO_SLUG = 'owner/repo';
12+
delete process.env.BUDDY_EXECUTION_PULL_REQUEST_ID;
13+
14+
t.deepEqual(appveyor.configuration(), {
15+
name: 'Buddy',
16+
service: 'buddy',
17+
commit: '5678',
18+
build: '5',
19+
buildUrl:
20+
'https://app.buddy.works/pierredenisvanduynslager/playground/pipelines/pipeline/1111/execution/5b92a93863115e06fe4f7129',
21+
branch: 'master',
22+
pr: undefined,
23+
isPr: false,
24+
slug: 'owner/repo',
25+
});
26+
});
27+
28+
test('PR', t => {
29+
process.env.BUDDY_WORKSPACE_ID = '111';
30+
process.env.BUDDY_EXECUTION_ID = '5';
31+
process.env.BUDDY_EXECUTION_URL =
32+
'https://app.buddy.works/pierredenisvanduynslager/playground/pipelines/pipeline/1111/execution/5b92a93863115e06fe4f7129';
33+
process.env.BUDDY_EXECUTION_REVISION = '5678';
34+
process.env.BUDDY_EXECUTION_BRANCH = 'master';
35+
process.env.BUDDY_REPO_SLUG = 'owner/repo';
36+
process.env.BUDDY_EXECUTION_PULL_REQUEST_ID = '10';
37+
38+
t.deepEqual(appveyor.configuration(), {
39+
name: 'Buddy',
40+
service: 'buddy',
41+
commit: '5678',
42+
build: '5',
43+
buildUrl:
44+
'https://app.buddy.works/pierredenisvanduynslager/playground/pipelines/pipeline/1111/execution/5b92a93863115e06fe4f7129',
45+
branch: 'master',
46+
pr: '10',
47+
isPr: true,
48+
slug: 'owner/repo',
49+
});
50+
});

test/index.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ test.beforeEach(() => {
1212
delete process.env.bamboo_agentId;
1313
delete process.env.BITBUCKET_BUILD_NUMBER;
1414
delete process.env.BITRISE_IO;
15+
delete process.env.BUDDY_WORKSPACE_ID;
1516
delete process.env.BUILDKITE;
1617
delete process.env.CIRCLECI;
1718
delete process.env.CIRRUS_CI;
@@ -65,6 +66,14 @@ test.serial('Bitrise', t => {
6566
t.is(env.service, 'bitrise');
6667
});
6768

69+
test.serial('Buddy', t => {
70+
process.env.BUDDY_WORKSPACE_ID = '1234';
71+
72+
const env = m();
73+
t.is(env.isCi, true);
74+
t.is(env.service, 'buddy');
75+
});
76+
6877
test.serial('Buildkite', t => {
6978
process.env.BUILDKITE = 'true';
7079

0 commit comments

Comments
 (0)