Skip to content

Commit

Permalink
feat: Cloudflare Pages (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Oct 25, 2021
1 parent 7bca59d commit 1f504fd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ if (isCI) {
| [Buildkite](https://buildkite.com/docs/builds/environment-variables) | `buildkite` | :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: |
| [CircleCI](https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables) | `circleci` | :white_check_mark: | [:warning:](#circleci) | :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: | :x: |
| [Cirrus CI](https://cirrus-ci.org/guide/writing-tasks/#environment-variables) | `cirrus` | :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: |
| [Cloudflare Pages](https://developers.cloudflare.com/pages/platform/build-configuration#environment-variables) | `cloudflarePages` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: |
| [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html) | `codebuild` | :white_check_mark: | [:warning:](#aws-codebuild) | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: |
| [Codefresh](https://codefresh.io/docs/docs/codefresh-yaml/variables#system-provided-variables) | `codefresh` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
| [Codeship](https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables/#default-environment-variables) | `codeship` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :x: |
Expand Down Expand Up @@ -147,6 +148,10 @@ Therefore in the case of Pull Request builds, `env-ci` will not be able to deter

See [feature request](https://discuss.circleci.com/t/create-a-circle-target-branch-envar/10022).

### Cloudflare Pages

For builds triggered when a Pull Request is opened/updated, Cloudflare Pages will re-use the branch variable for the originating branch and not provide a target. Therefore `env-ci` will not be able to determine the `prBranch` property however `branch` will always be set.

### Jenkins

Triggering build when a Pull Request is opened/updated is supported only via the [ghprb-plugin](https://github.com/jenkinsci/ghprb-plugin) and [gitlab-plugin](https://github.com/jenkinsci/gitlab-plugin). Therefore `env-ci` will set `isPr`, `pr` and `prBranch` and define `branch` with the Pull Request target branch only if one those plugin is used.
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const services = {
buildkite: require('./services/buildkite.js'),
circleci: require('./services/circleci.js'),
cirrus: require('./services/cirrus.js'),
cloudflarePages: require('./services/cloudflare-pages.js'),
codebuild: require('./services/codebuild.js'),
codefresh: require('./services/codefresh.js'),
codeship: require('./services/codeship.js'),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"ci",
"circle",
"cirrus",
"cloudflare",
"codebuild",
"codefresh",
"codeship",
Expand Down
16 changes: 16 additions & 0 deletions services/cloudflare-pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// https://developers.cloudflare.com/pages/platform/build-configuration#environment-variables

module.exports = {
detect({env}) {
return env.CF_PAGES === '1';
},
configuration({env}) {
return {
name: 'Cloudflare Pages',
service: 'cloudflarePages',
commit: env.CF_PAGES_COMMIT_SHA,
branch: env.CF_PAGES_BRANCH,
root: env.PWD,
};
},
};
19 changes: 19 additions & 0 deletions test/services/cloudflare-pages.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const test = require('ava');
const cloudflarePages = require('../../services/cloudflare-pages.js');

const env = {
CF_PAGES: '1',
CF_PAGES_COMMIT_SHA: '6792f396eadca08926a7c810b7b77fa3815db1f4',
CF_PAGES_BRANCH: 'main',
PWD: '/opt/buildhome/repo',
};

test('Push', (t) => {
t.deepEqual(cloudflarePages.configuration({env}), {
name: 'Cloudflare Pages',
service: 'cloudflarePages',
commit: '6792f396eadca08926a7c810b7b77fa3815db1f4',
branch: 'main',
root: '/opt/buildhome/repo',
});
});

0 comments on commit 1f504fd

Please sign in to comment.