💸Save up to $132K/month in CI costs!👉 Try Free
Skip to main content
← Back to workflows

How to Use GitHub Action for Creating Cloudflare Pages Deployments

cloudflare/pages-action -
GitHub Action
v1.5.0
476
Contributors
Contributor - WalshyDevContributor - aaronadamsCAContributor - GregBrimble
Categories

Optimize Your CI/CD Pipeline

Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.

45% Faster Builds
60% Cost Reduction
Usage
on: [push]

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
name: Publish to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1

pages-action logo

pages-action

null


Now, you can create deployments with the GitHub Action for Cloudflare Pages. It integrates with Wrangler's ability to Direct Upload

It seems there was an issue with processing your request. I'll try again to humanize the text. One moment, please.

Now, you can create deployments with the GitHub Action for Cloudflare Pages. It integrates with Wrangler's ability to Direct Upload, and you will set it up like this:.

How to Specifiyig the Branch

Cloudflare Pages will use the branch name to determine if the deployment is for Production or Preview. Wrangler already attempts to pull that information, but you can explicitly set the branch by adding the argument branch: YOUR_BRANCH_NAME.

They are specifying the branch aids in the distinction between production and preview environments so that proper workflows for deploying can be maintained.

Setting the Working Directory By default, Wrangler will run in the root directory. If your app resides in a mono-repo or a specific sub-directory, you will set workingDirectory: YOUR_PACKAGE_DIRECTORY.

In projects with a pretty complex structure of the directories, it may be essential to set the working directory so that the deployment can point to the correct building output.

Sample Workflow Configuration

Here is an example of a full GitHub Workflow to deploy to Cloudflare Pages: This setup in the workflow part should make sure there is always seamless deployment to Cloudflare Pages, with a few possible customizations to suit varied project requirements. This furthers the empowerment of your CI/CD pipeline through the automation of deployments and maintaining version control.

on: [push]

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
name: Publish to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v3

# Run a build step here if your project requires

- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: YOUR_ACCOUNT_ID
projectName: YOUR_PROJECT_NAME
directory: YOUR_BUILD_OUTPUT_DIRECTORY
# Optional: Enable this if you want to have GitHub Deployments triggered
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
# Optional: Switch what branch you are publishing to.
# By default this will be the branch which triggered this workflow
branch: main
# Optional: Change the working directory
workingDirectory: my-site
# Optional: Change the Wrangler version, allows you to point to a specific version or a tag such as `beta`
wranglerVersion: '3'