Skip to content

Commit

Permalink
feat(vela): Adds Vela CI provider (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
10hendersonm committed Dec 3, 2021
1 parent 8814f92 commit 5733594
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ if (isCI) {
| [Shippable](http://docs.shippable.com/ci/env-vars/#stdEnv) | `shippable` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| [TeamCity](https://confluence.jetbrains.com/display/TCD10/Predefined+Build+Parameters) | `teamcity` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: |
| [Travis CI](https://docs.travis-ci.com/user/environment-variables#default-environment-variables) | `travis` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| [Vela](https://go-vela.github.io/docs/reference/environment/variables/) | `vela` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| [Vercel](https://vercel.com/docs/environment-variables) | `vercel` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :x: |
| [Visual Studio Team Services](https://docs.microsoft.com/en-us/vsts/pipelines/build/variables) | `vsts` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| [Wercker](http://devcenter.wercker.com/docs/environment-variables/available-env-vars#hs_cos_wrapper_name) | `wercker` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: |
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const services = {
shippable: require('./services/shippable.js'),
teamcity: require('./services/teamcity.js'),
travis: require('./services/travis.js'),
vela: require('./services/vela.js'),
vercel: require('./services/vercel.js'),
vsts: require('./services/vsts.js'),
wercker: require('./services/wercker.js'),
Expand Down
27 changes: 27 additions & 0 deletions services/vela.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// https://go-vela.github.io/docs/reference/environment/variables/

module.exports = {
detect({env}) {
return Boolean(env.VELA);
},
configuration({env}) {
const isPr = env.VELA_BUILD_EVENT === 'pull_request';

return {
name: 'Vela',
service: 'vela',
branch: isPr ? env.VELA_PULL_REQUEST_TARGET : env.VELA_BUILD_BRANCH,
commit: env.VELA_BUILD_COMMIT,
tag: env.VELA_BUILD_TAG,
build: env.VELA_BUILD_NUMBER,
buildUrl: env.VELA_BUILD_LINK,
job: undefined,
jobUrl: undefined,
isPr,
pr: env.VELA_BUILD_PULL_REQUEST,
prBranch: env.VELA_PULL_REQUEST_SOURCE,
slug: env.VELA_REPO_FULL_NAME,
root: env.VELA_BUILD_WORKSPACE,
};
},
};
7 changes: 7 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ test('Travis', (t) => {
t.is(service, 'travis');
});

test('Vela', (t) => {
const {isCi, service} = m({env: {VELA: 'true'}});

t.is(isCi, true);
t.is(service, 'vela');
});

test('Visual Studio Team Services', (t) => {
const {isCi, service} = m({env: {BUILD_BUILDURI: 'https://fabrikamfiber.visualstudio.com/_git/Scripts'}});

Expand Down
91 changes: 91 additions & 0 deletions test/services/vela.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const test = require('ava');
const vela = require('../../services/vela.js');

const env = {
VELA: 'true',
VELA_BUILD_EVENT: 'push',
VELA_BUILD_BRANCH: 'my-branch',
VELA_BUILD_COMMIT: 'a1b2c3',
VELA_BUILD_NUMBER: '25',
VELA_BUILD_LINK: 'https://some-vela-instance.com/Org/Project/25',
VELA_REPO_FULL_NAME: 'Org/Project',
VELA_BUILD_WORKSPACE: '/home/Org/Project',
};

test('Push', (t) => {
t.deepEqual(vela.configuration({env}), {
name: 'Vela',
service: 'vela',
commit: 'a1b2c3',
tag: undefined,
build: '25',
buildUrl: 'https://some-vela-instance.com/Org/Project/25',
branch: 'my-branch',
job: undefined,
jobUrl: undefined,
isPr: false,
pr: undefined,
prBranch: undefined,
slug: 'Org/Project',
root: '/home/Org/Project',
});
});

test('PR', (t) => {
t.deepEqual(
vela.configuration({
env: {
...env,
VELA_BUILD_EVENT: 'pull_request',
VELA_BUILD_PULL_REQUEST: '1',
VELA_PULL_REQUEST_TARGET: 'main',
VELA_PULL_REQUEST_SOURCE: 'my-branch',
VELA_BUILD_BRANCH: 'my-branch',
},
}),
{
name: 'Vela',
service: 'vela',
commit: 'a1b2c3',
tag: undefined,
build: '25',
buildUrl: 'https://some-vela-instance.com/Org/Project/25',
branch: 'main',
job: undefined,
jobUrl: undefined,
isPr: true,
pr: '1',
prBranch: 'my-branch',
slug: 'Org/Project',
root: '/home/Org/Project',
}
);
});

test('Tag', (t) => {
t.deepEqual(
vela.configuration({
env: {
...env,
VELA_BUILD_EVENT: 'tag',
VELA_BUILD_TAG: 'v1.0.2',
},
}),
{
name: 'Vela',
service: 'vela',
commit: 'a1b2c3',
tag: 'v1.0.2',
build: '25',
buildUrl: 'https://some-vela-instance.com/Org/Project/25',
branch: 'my-branch',
job: undefined,
jobUrl: undefined,
isPr: false,
pr: undefined,
prBranch: undefined,
slug: 'Org/Project',
root: '/home/Org/Project',
}
);
});

0 comments on commit 5733594

Please sign in to comment.