Skip to content

Commit

Permalink
Merge pull request #19 from spencerreeves/main
Browse files Browse the repository at this point in the history
Add support for specifying branch
  • Loading branch information
WalshyDev authored Jul 26, 2022
2 parents 212ce69 + c585f13 commit c4f0d2e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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(
Expand Down

0 comments on commit c4f0d2e

Please sign in to comment.