Skip to content

Commit

Permalink
Add WoodpeckerCI
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Jul 20, 2022
1 parent 6877f72 commit a6d0bec
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
14 changes: 14 additions & 0 deletions .woodpecker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# config for woodpecker: https://woodpecker-ci.org/docs/usage/pipeline-syntax

pipeline:
build:
image: node:10
environment:
- NODE_ENV=development
- NPM_CONFIG_LOGLEVEL=warn
commands:
- env | sort
- npm install
- npm run test
when:
event: [ pull_request, push ]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

 

Supports travis, circle, gitlab, wercker, drone, codeship, now(zeit), netlify, GitHub Actions, Buddy, Codefresh and Cloudflare Pages.
Supports travis, circle, gitlab, wercker, drone, codeship, now(zeit), netlify, GitHub Actions, Buddy, Codefresh, Cloudflare Pages and [WoodpeckerCI](https://woodpecker-ci.org).

Kinda supports custom CI as well. [Specs here](https://github.com/siddharthkp/ci-env/blob/master/index.js#L68-L79)

Expand Down
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ if (process.env.TRAVIS) {
buildUrl = process.env.CF_BUILD_URL;
platform = 'codefresh';
ci = 'codefresh';
} else if (process.env.CI === 'woodpecker') {
// Reference: https://woodpecker-ci.org/docs/usage/environment#built-in-environment-variables
repo = process.env.CI_REPO;
sha = process.env.CI_COMMIT_SHA;
event = process.env.CI_BUILD_EVENT;
commit_message = process.env.CI_COMMIT_MESSAGE;
pull_request_number = process.env.CI_COMMIT_PULL_REQUEST;
pull_request_target_branch = process.env.CI_COMMIT_TARGET_BRANCH;
branch = process.env.CI_COMMIT_BRANCH;
buildUrl = process.env.CI_BUILD_LINK;
jobUrl = process.env.CI_BUILD_LINK;
platform = 'woodpecker';
ci = 'woodpecker';
} else if (process.env.CI) {
// Generic variables for docker images, custom CI builds, etc.

Expand Down
38 changes: 25 additions & 13 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if (ci) {
else if (process.env.WERCKER) t.is(ci, "wercker");
else if (process.env.DRONE) t.is(ci, "drone");
else if (process.env.CI_NAME === "codeship") t.is(ci, "codeship");
else if (process.env.CI === "woodpecker") t.is(ci, "woodpecker");
else if (process.env.GITHUB_ACTION) t.is(ci, "github_actions");
else if (process.env.GITLAB_CI) t.is(ci, "gitlab");
else if (process.env.CF_BUILD_URL) t.is(ci, "codefresh");
Expand All @@ -49,7 +50,7 @@ if (ci) {
process.env.WERCKER_GIT_COMMIT ||
process.env.DRONE_COMMIT ||
process.env.GITHUB_SHA ||
process.env.CI_COMMIT_SHA || //gitlab
process.env.CI_COMMIT_SHA || //gitlab & woodpecker
process.env.CF_REVISION ||
process.env.CF_PAGES_COMMIT_SHA;

Expand All @@ -62,6 +63,7 @@ if (ci) {
process.env.CI_COMMIT_MESSAGE ||
process.env.CI_MESSAGE ||
process.env.CF_COMMIT_MESSAGE ||
process.env.CI_COMMIT_MESSAGE || // woodpecker
"";
// Only travis and codeship set commit message
t.is(commit_message, real_commit_message);
Expand All @@ -77,39 +79,48 @@ if (ci) {
const real_pull_request_number =
process.env.TRAVIS_PULL_REQUEST ||
process.env.DRONE_PULL_REQUEST ||
process.env.CI_MERGE_REQUEST_ID || //gitlab
process.env.CI_MERGE_REQUEST_ID || // gitlab
process.env.CF_PULL_REQUEST_NUMBER ||
process.env.CI_COMMIT_PULL_REQUEST || // woodpecker
pullRequestNumber ||
""; // wercker does not expose pull request number

t.is(pull_request_number, real_pull_request_number);
});

test("jobUrl is set", t => {
let real_jobUrl;
let realJobUrl;
if (process.env.TRAVIS)
real_jobUrl = `https://travis-ci.org/${repo}/jobs/${
realJobUrl = `https://travis-ci.org/${repo}/jobs/${
process.env.TRAVIS_JOB_ID
}`;
else if (process.env.GITLAB_CI) real_jobUrl = process.env.CI_JOB_URL;
t.is(jobUrl, real_jobUrl);
else if (process.env.GITLAB_CI) realJobUrl = process.env.CI_JOB_URL;

const real_job_url =
process.env.CI_BUILD_LINK ||
realJobUrl;
t.is(jobUrl, real_job_url);
});

test("buildUrl is set", t => {
let real_buildUrl;
let realBuildUrl;
if (process.env.TRAVIS)
real_buildUrl = `https://travis-ci.org/${repo}/builds/${
realBuildUrl = `https://travis-ci.org/${repo}/builds/${
process.env.TRAVIS_JOB_ID
}`;
else if (process.env.CF_BUILD_URL) real_buildUrl = process.env.CF_BUILD_URL;
t.is(buildUrl, real_buildUrl);
else if (process.env.CF_BUILD_URL) realBuildUrl = process.env.CF_BUILD_URL;

const real_build_url =
process.env.CI_BUILD_LINK ||
realBuildUrl;
t.is(buildUrl, real_build_url);
});

test("event is correctly set", t => {
if (
(ci === "travis" && process.env.TRAVIS_EVENT_TYPE === "pull_request") ||
(ci === "github_actions" &&
process.env.GITHUB_EVENT_NAME === "pull_request")
(ci === "github_actions" && process.env.GITHUB_EVENT_NAME === "pull_request") ||
(ci === "woodpecker" && process.env.CI_BUILD_EVENT === "pull_request")
)
t.is(event, "pull_request");
else t.is(event, "push");
Expand All @@ -119,7 +130,7 @@ if (ci) {
if (event === "pull_request")
t.is(
branch,
process.env.TRAVIS_PULL_REQUEST_BRANCH || process.env.GITHUB_HEAD_REF
process.env.TRAVIS_PULL_REQUEST_BRANCH || process.env.GITHUB_HEAD_REF || process.env.CI_COMMIT_TARGET_BRANCH
);
else {
const real_branch =
Expand All @@ -129,6 +140,7 @@ if (ci) {
process.env.DRONE_BRANCH ||
process.env.CI_BRANCH || // codeship
process.env.CI_COMMIT_REF_NAME || // gitlab
process.env.CI_COMMIT_BRANCH // woodpecker
process.env.CF_BRANCH ||
process.env.CF_PAGES_BRANCH ||
process.env.GITHUB_REF.split('/')[2];
Expand Down

0 comments on commit a6d0bec

Please sign in to comment.