Skip to content
Latchkey

CI/CD for an Astro App on Cloudflare with GitHub Actions

Run astro check, build, and deploy your Astro site to Cloudflare with Wrangler on every push.

Astro builds fast static or SSR output that fits Cloudflare perfectly. This recipe runs astro check for content and type validation, builds the site, and deploys with Wrangler using the Cloudflare adapter.

What the pipeline does

  • install deps with npm ci
  • run astro check
  • build with astro build
  • deploy with wrangler
  • gate the deploy on main

The workflow

astro check validates types and content collections. wrangler deploy ships the built output using the Cloudflare adapter target configured in astro.config.

.github/workflows/ci.yml
name: CI
on:
  push:
    branches: [main]
  pull_request:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - run: npm ci
      - run: npm run astro -- check
      - run: npm run build
      - if: github.ref == 'refs/heads/main'
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
          command: deploy

Caching and speed

cache: npm restores node_modules quickly. Astro builds are CPU-bound for large content collections; running them on cheaper managed runners such as Latchkey (around 69% cheaper than GitHub-hosted) keeps preview builds fast and auto-retries a flaky npm registry fetch.

Deploying

Create a Cloudflare API token scoped to Workers and Pages, plus your account ID, and store both as secrets. For a static-only site, target Cloudflare Pages with wrangler pages deploy ./dist; for SSR, use the @astrojs/cloudflare adapter and wrangler deploy.

Key takeaways

  • Run astro check to catch content-collection and type errors before deploy.
  • Use a scoped Cloudflare API token for Wrangler, not a global key.
  • Pick Pages for static output and the Cloudflare adapter for SSR.

Related guides

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