How to Deploy to Cloudflare Pages from GitHub Actions
Wrangler pushes a built directory to a Cloudflare Pages project in one command.
Build the site, then run wrangler pages deploy with CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID set.
Steps
- Create a Cloudflare API token with Pages edit permission; add
CLOUDFLARE_API_TOKEN. - Add
CLOUDFLARE_ACCOUNT_IDas a secret or variable. - Build, then deploy the output dir to your Pages project.
Workflow
.github/workflows/deploy.yml
jobs:
deploy:
runs-on: ubuntu-latest
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
steps:
- uses: actions/checkout@v4
- run: npm ci && npm run build
- run: npx wrangler pages deploy dist --project-name=my-siteGotchas
- The project must already exist in the Cloudflare dashboard before the first deploy.
- Use
--branchto target a Pages preview branch instead of production.
Related guides
How to Deploy to Netlify from GitHub ActionsDeploy a static site to Netlify from GitHub Actions with the Netlify CLI, using an auth token and site ID so…
How to Deploy to Vercel from GitHub ActionsDeploy a project to Vercel from GitHub Actions using the Vercel CLI and a scoped token so production deploys…