From 1f504fde1505be788e51a49e98e12433e3174f05 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Mon, 25 Oct 2021 18:43:55 +0100 Subject: [PATCH] feat: Cloudflare Pages (#156) --- README.md | 5 +++++ index.js | 1 + package.json | 1 + services/cloudflare-pages.js | 16 ++++++++++++++++ test/services/cloudflare-pages.test.js | 19 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 services/cloudflare-pages.js create mode 100644 test/services/cloudflare-pages.test.js diff --git a/README.md b/README.md index 8a95b33..f7646a1 100644 --- a/README.md +++ b/README.md @@ -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: | @@ -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. diff --git a/index.js b/index.js index 8371cd5..d0e08d4 100644 --- a/index.js +++ b/index.js @@ -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'), diff --git a/package.json b/package.json index 13d1aa9..73ed779 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "ci", "circle", "cirrus", + "cloudflare", "codebuild", "codefresh", "codeship", diff --git a/services/cloudflare-pages.js b/services/cloudflare-pages.js new file mode 100644 index 0000000..eb8afcd --- /dev/null +++ b/services/cloudflare-pages.js @@ -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, + }; + }, +}; diff --git a/test/services/cloudflare-pages.test.js b/test/services/cloudflare-pages.test.js new file mode 100644 index 0000000..a8cec44 --- /dev/null +++ b/test/services/cloudflare-pages.test.js @@ -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', + }); +});