Skip to content

Commit

Permalink
feat: add woodpecker-ci support (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten authored Jul 19, 2022
1 parent 2ab058c commit 0ebad85
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()} = {}) => {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"teamcity",
"travis",
"variable",
"wercker"
"wercker",
"woodpecker"
],
"license": "MIT",
"main": "index.js",
Expand Down
27 changes: 27 additions & 0 deletions services/woodpecker.js
Original file line number Diff line number Diff line change
@@ -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,
};
},
};
7 changes: 7 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
64 changes: 64 additions & 0 deletions test/services/woodpecker.test.js
Original file line number Diff line number Diff line change
@@ -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',
}
);
});

0 comments on commit 0ebad85

Please sign in to comment.