From c585f13e3e25884f5d4f83cb558e3f1fbc912256 Mon Sep 17 00:00:00 2001 From: Spencer Reeves Date: Wed, 29 Jun 2022 18:31:02 -0700 Subject: [PATCH] Add support for specifying branch (#1) --- README.md | 7 +++++++ action.yml | 3 +++ index.js | 3 ++- src/index.ts | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8f1a53a..820542f 100644 --- a/README.md +++ b/README.md @@ -52,3 +52,10 @@ To generate an API token: 7. Select Continue to summary > Create Token. More information can be found on [our guide for making Direct Upload deployments with continous integration](https://developers.cloudflare.com/pages/how-to/use-direct-upload-with-continuous-integration/#use-github-actions). + +### Specifying a branch +The branch name is used by Cloudflare Pages to determine if the deployment is production or preview. Read more about +[git branch build controls](https://developers.cloudflare.com/pages/platform/branch-build-controls/#branch-build-controls). + +If you are in a Git workspace, Wrangler will automatically pull the branch information for you. You can override this +manually by adding the argument `branch: YOUR_BRANCH_NAME`. \ No newline at end of file diff --git a/action.yml b/action.yml index 8a03f63..1bdb02c 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,9 @@ inputs: gitHubToken: description: "GitHub Token" required: true + branch: + description: "The name of the branch you want to deploy to" + required: false runs: using: "node16" main: "index.js" diff --git a/index.js b/index.js index f1768cc..58fa930 100644 --- a/index.js +++ b/index.js @@ -16115,6 +16115,7 @@ try { const projectName = (0, import_core.getInput)("projectName", { required: true }); const directory = (0, import_core.getInput)("directory", { required: true }); const gitHubToken = (0, import_core.getInput)("gitHubToken", { required: true }); + const branch = (0, import_core.getInput)("branch", { required: false }); const octokit = (0, import_github.getOctokit)(gitHubToken); const createPagesDeployment = async () => { await esm_default` @@ -16123,7 +16124,7 @@ try { $ export CLOUDFLARE_ACCOUNT_ID="${accountId}" } - $$ npx wrangler@2 pages publish "${directory}" --project-name="${projectName}" + $$ npx wrangler@2 pages publish "${directory}" --project-name="${projectName}" --branch="${branch}" `; const response = await (0, import_undici.fetch)(`https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects/${projectName}/deployments`, { headers: { Authorization: `Bearer ${apiToken}` } }); const { diff --git a/src/index.ts b/src/index.ts index 3f1eadf..8b57e0c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,6 +53,7 @@ try { const projectName = getInput("projectName", { required: true }); const directory = getInput("directory", { required: true }); const gitHubToken = getInput("gitHubToken", { required: true }); + const branch = getInput("branch", { required: false }); const octokit = getOctokit(gitHubToken); @@ -64,7 +65,7 @@ try { $ export CLOUDFLARE_ACCOUNT_ID="${accountId}" } - $$ npx wrangler@2 pages publish "${directory}" --project-name="${projectName}" + $$ npx wrangler@2 pages publish "${directory}" --project-name="${projectName}" --branch="${branch}" `; const response = await fetch(