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 checkoutand re-tagging with arollback-*tag. - Static files in
./publicare deployed directly usingwrangler.
π§ Prerequisites
1. Install and Configure wrangler.toml
Root of your repository
# wrangler.toml
name = "github-action-tag"
pages_build_output_dir = "./public"2. Create a Cloudflare API Token
Generate token here: π Cloudflare API Token Settings (opens in a new tab)
Required permissions:
- Account β Cloudflare Pages β Edit
- Zone β Read
- (Optional) Restrict by account or project
Store it in your GitHub repo:
Settings > Secrets and variables > Actions > New repository secret
Name: CLOUDFLARE_API_TOKENπ οΈ GitHub Actions Workflow
.github/workflows/cf.yaml
name: Deploy Tagged Release to Cloudflare Pages
on:
push:
tags:
- 'v*'
- 'rollback-*'
- 'hotfix-*'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Tag
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Set Up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Wrangler
run: npm install -g wrangler
- name: Deploy to Cloudflare Pages (Production)
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: |
wrangler pages deploy ./public \
--project-name github-action-tag \
#verify this in pages is set to production
--branch main
π Deployment Usage
π Normal Deployment
# Make changes
git add .
git commit -m "feature added"
git push origin main
# Tag release
git tag v11
git push --tagsβ Automatically deploys tag
v11to production (Cloudflare Pages βmainbranch)
π§― Rollback to Previous Tag
Step-by-step:
# Suppose v11 caused issues, and v10 was stable
git checkout v10 # Checkout the working tag
git tag rollback-v10 # Create rollback tag
git push --tags # Push rollback tagβ This will re-trigger the deployment to production using the
v10commit
π§ͺ Example Tags You Can Use
| Tag Name | Purpose |
|---|---|
v1, v2 | Normal release |
hotfix-v2 | Emergency patch |
rollback-v1 | Rollback to old tag |
π Notes
- Cloudflare uses the
--branch mainflag 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
./publicas the deployment directory (you can customize viawrangler.toml). - You must use Node.js v20+ as required by Wrangler 4.x.
β Final Checklist
-
wrangler.tomlwithpages_build_output_dir - GitHub secret:
CLOUDFLARE_API_TOKEN - GitHub Action workflow deployed on tag
- Use
rollback-*tags to trigger safe rollback