Skip to content
Latchkey

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_ID as 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-site

Gotchas

  • The project must already exist in the Cloudflare dashboard before the first deploy.
  • Use --branch to target a Pages preview branch instead of production.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →