From 57335942659785fb1650e96e643c66146871ab80 Mon Sep 17 00:00:00 2001 From: Marty Henderson <10hendersonm@gmail.com> Date: Fri, 3 Dec 2021 09:47:09 -0600 Subject: [PATCH] feat(vela): Adds Vela CI provider (#170) --- README.md | 1 + index.js | 1 + services/vela.js | 27 +++++++++++ test/index.test.js | 7 +++ test/services/vela.test.js | 91 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 services/vela.js create mode 100644 test/services/vela.test.js diff --git a/README.md b/README.md index f7646a1..042d2a9 100644 --- a/README.md +++ b/README.md @@ -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: | diff --git a/index.js b/index.js index d0e08d4..b363d35 100644 --- a/index.js +++ b/index.js @@ -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'), diff --git a/services/vela.js b/services/vela.js new file mode 100644 index 0000000..e92d409 --- /dev/null +++ b/services/vela.js @@ -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, + }; + }, +}; diff --git a/test/index.test.js b/test/index.test.js index 4839359..b950d05 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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'}}); diff --git a/test/services/vela.test.js b/test/services/vela.test.js new file mode 100644 index 0000000..e6d80e3 --- /dev/null +++ b/test/services/vela.test.js @@ -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', + } + ); +});