Skip to main content

Cloudflare Pages Deployment via GitHub Tags

This setup ensures:
  • Every versioned tag (v*), hotfix (hotfix-*), or rollback (rollback-*) deployment is deployed to production.
  • Rollbacks can be done easily using git checkout and re-tagging with a rollback-* tag.
  • Static files in ./public are deployed directly using wrangler.

๐Ÿ”ง Prerequisites

1. Install and Configure wrangler.toml

Root of your repository

2. Create a Cloudflare API Token

Generate token here: ๐Ÿ”— Cloudflare API Token Settings Required permissions:
  • Account โ†’ Cloudflare Pages โ†’ Edit
  • Zone โ†’ Read
  • (Optional) Restrict by account or project
Store it in your GitHub repo:

๐Ÿ› ๏ธ GitHub Actions Workflow

.github/workflows/cf.yaml

๐Ÿš€ Deployment Usage

๐Ÿ”„ Normal Deployment

โœ… Automatically deploys tag v11 to production (Cloudflare Pages โ†’ main branch)

๐Ÿงฏ Rollback to Previous Tag

Step-by-step:

โœ… This will re-trigger the deployment to production using the v10 commit

๐Ÿงช Example Tags You Can Use


๐Ÿ“ Notes

  • Cloudflare uses the --branch main flag to treat this as a production deployment.
  • Tags point to commits, so you can roll back by creating a new tag from an older commit.
  • Wrangler uses ./public as the deployment directory (you can customize via wrangler.toml).
  • You must use Node.js v20+ as required by Wrangler 4.x.

โœ… Final Checklist

  • wrangler.toml with pages_build_output_dir
  • GitHub secret: CLOUDFLARE_API_TOKEN
  • GitHub Action workflow deployed on tag
  • Use rollback-* tags to trigger safe rollback