diff --git a/README.md b/README.md index b99bdfd..9e57402 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ if (isCI) { ## Supported CI | CI Service (`name`) | `service` | `isCi` | `branch` | `commit` | `tag` | `build` | `buildUrl` | `job` | `jobUrl` | `isPr` | `pr` | `prBranch` | `slug` | `root` | -|----------------------------------------------------------------------------------------------------------------------------------------|:-----------------:|:------------------:|:---------------------------:|:------------------:|:-----------------------:|:------------------:|:------------------:|:------------------:|:------------------:|:---------------------:|:---------------------:|:---------------------:|:------------------:|:------------------:| +| -------------------------------------------------------------------------------------------------------------------------------------- | :---------------: | :----------------: | :-------------------------: | :----------------: | :---------------------: | :----------------: | :----------------: | :----------------: | :----------------: | :-------------------: | :-------------------: | :-------------------: | :----------------: | :----------------: | | [AppVeyor](https://www.appveyor.com/docs/environment-variables) | `appveyor` | :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: | | [Azure Pipelines](https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables) | `azure-devops` | :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: | | [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html) | `bamboo` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | @@ -93,6 +93,7 @@ if (isCI) { | [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: | | [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: | | [JetBrains Space](https://www.jetbrains.com/space/) | `jetbrainsSpace` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :x: | +| [Woodpecker CI](https://woodpecker-ci.org/docs/usage/environment#built-in-environment-variables) | `woodpecker` | :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: | :warning: See [Caveats](#caveats) diff --git a/index.js b/index.js index 173b0ff..17347e0 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,7 @@ const services = { vela: require('./services/vela.js'), vercel: require('./services/vercel.js'), wercker: require('./services/wercker.js'), + woodpecker: require('./services/woodpecker.js'), }; module.exports = ({env = process.env, cwd = process.cwd()} = {}) => { diff --git a/package.json b/package.json index f73f72e..95046e3 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,8 @@ "teamcity", "travis", "variable", - "wercker" + "wercker", + "woodpecker" ], "license": "MIT", "main": "index.js", diff --git a/services/woodpecker.js b/services/woodpecker.js new file mode 100644 index 0000000..ad2be45 --- /dev/null +++ b/services/woodpecker.js @@ -0,0 +1,27 @@ +// https://woodpecker-ci.org/docs/usage/environment#built-in-environment-variables + +module.exports = { + detect({env}) { + return env.CI && env.CI === 'woodpecker'; + }, + configuration({env}) { + const isPr = env.CI_BUILD_EVENT === 'pull_request'; + + return { + name: 'Woodpecker CI', + service: 'woodpecker', + commit: env.CI_COMMIT_SHA, + tag: env.CI_COMMIT_TAG, + build: env.CI_BUILD_NUMBER, + buildUrl: env.CI_BUILD_LINK, + branch: isPr ? env.CI_COMMIT_TARGET_BRANCH : env.CI_COMMIT_BRANCH, + job: env.CI_JOB_NUMBER, + jobUrl: env.CI_BUILD_LINK, + pr: env.CI_COMMIT_PULL_REQUEST, + isPr, + prBranch: isPr ? env.CI_COMMIT_SOURCE_BRANCH : undefined, + slug: `${env.CI_REPO_OWNER}/${env.CI_REPO_NAME}`, + root: env.CI_WORKSPACE, + }; + }, +}; diff --git a/test/index.test.js b/test/index.test.js index 5ca7eeb..f8c98e7 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -186,6 +186,13 @@ test('Wercker', (t) => { t.is(service, 'wercker'); }); +test('Woodpecker CI', (t) => { + const {isCi, service} = m({env: {CI: 'woodpecker'}}); + + t.is(isCi, true); + t.is(service, 'woodpecker'); +}); + test('Unknown CI and Git repository', async (t) => { const {cwd} = await gitRepo(); await gitCommit('Test commit message', {cwd}); diff --git a/test/services/woodpecker.test.js b/test/services/woodpecker.test.js new file mode 100644 index 0000000..bf8935b --- /dev/null +++ b/test/services/woodpecker.test.js @@ -0,0 +1,64 @@ +const test = require('ava'); +const woodpecker = require('../../services/woodpecker.js'); + +const env = { + CI: 'woodpecker', + CI_JOB_NUMBER: '1234', + CI_BUILD_LINK: 'https://woodpecker-ci.example.com/owner/repo/91011', + CI_COMMIT_SHA: '5678', + CI_COMMIT_TAG: 'tag_name', + CI_BUILD_NUMBER: '91011', + CI_COMMIT_BRANCH: 'main', + CI_REPO_OWNER: 'owner', + CI_REPO_NAME: 'repo', + CI_WORKSPACE: '/woodpecker/src/github.com/owner/repo', +}; + +test('Push', (t) => { + t.deepEqual(woodpecker.configuration({env}), { + name: 'Woodpecker CI', + service: 'woodpecker', + commit: '5678', + tag: 'tag_name', + build: '91011', + buildUrl: 'https://woodpecker-ci.example.com/owner/repo/91011', + branch: 'main', + job: '1234', + jobUrl: 'https://woodpecker-ci.example.com/owner/repo/91011', + pr: undefined, + isPr: false, + prBranch: undefined, + slug: 'owner/repo', + root: '/woodpecker/src/github.com/owner/repo', + }); +}); + +test('PR', (t) => { + t.deepEqual( + woodpecker.configuration({ + env: { + ...env, + CI_COMMIT_PULL_REQUEST: '10', + CI_BUILD_EVENT: 'pull_request', + CI_COMMIT_TARGET_BRANCH: 'main', + CI_COMMIT_SOURCE_BRANCH: 'pr-branch', + }, + }), + { + name: 'Woodpecker CI', + service: 'woodpecker', + commit: '5678', + tag: 'tag_name', + build: '91011', + buildUrl: 'https://woodpecker-ci.example.com/owner/repo/91011', + branch: 'main', + job: '1234', + jobUrl: 'https://woodpecker-ci.example.com/owner/repo/91011', + pr: '10', + isPr: true, + prBranch: 'pr-branch', + slug: 'owner/repo', + root: '/woodpecker/src/github.com/owner/repo', + } + ); +});