Skip to content
Latchkey

How to Deploy a Static Site to Cloudflare Pages From CI

wrangler pages deploy uploads a build directory to a named Cloudflare Pages project using an API token.

Run wrangler pages deploy <dir> --project-name=<name> with CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID set, or use cloudflare/wrangler-action to wrap it in a workflow step.

Steps

  • Create a Cloudflare API token with the Pages Edit permission.
  • Store the token and account id as CI secrets.
  • Build the site, then run wrangler pages deploy.
  • Pass --project-name matching your Pages project.

Workflow

.github/workflows/ci.yml
on:
  push:
    branches: [main]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: pages deploy dist --project-name=my-site

Gotchas

  • The project must already exist in the Cloudflare dashboard or the deploy returns project not found.
  • Add --branch=main to control which Pages environment (production vs preview) receives the upload.
  • A wildcard token scoped to the wrong account fails with authentication error 10000.

Related guides

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