-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add woodpecker-ci support (#220)
- Loading branch information
Showing
6 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} | ||
); | ||
}); |