Repository navigation
ci: delete a branch's Cloudflare Pages previews when the branch is deleted - #263
Merged
Merged
Conversation
Adds a workflow that builds the site on every branch push and deploys it with wrangler to the Cloudflare Pages project named after the repository. main is the production deployment, other branches get a preview alias. The job skips itself while the Cloudflare secrets are missing. The GitHub Pages workflow stays in place until the switch is confirmed.
The Cloudflare API can fail the create call with code 8000000, which left the project missing and the deploy failing.
MathiasVDA
commented
Nov 26, 2026
MathiasVDA
left a comment
Collaborator
Author
There was a problem hiding this comment.
Review: OK to merge once the build check is green.
Checked the step script against a stubbed Cloudflare API (30 previews over two pages, mixed branches): it deletes exactly the deployments of the deleted branch, reports 0 for a branch without previews, exits cleanly when the project is missing or the secrets are absent, and fails on any other API error.
- Only
env=previewdeployments are listed, so production is out of reach. - The branch name comes in through
envandjq --arg, not through expression interpolation, and the job haspermissions: {}. - Collecting ids before deleting avoids skipping entries while paging.
Nit, not blocking: the paging loop has no upper bound; a timeout-minutes: 10 on the job would cap it if the API ever ignored page.
The branch also carries the earlier, already merged Cloudflare commits and a merge commit, so this goes in as a squash (the net diff is the one new file).
Generated by Claude Code
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
.github/workflows/cleanup-cloudflare-previews.yml. Cloudflare Pages keeps preview deployments after their branch is gone, so their URLs stay reachable. On a GitHubdeleteevent for a branch, this workflow:deployment_trigger.metadata.branchmatches the deleted branch,force=true, which also removes the branch alias.Production deployments (
env=production, i.e. main) are never listed, so they're never touched. It uses the existingCLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_IDsecrets, skips with a notice when they are missing or the project doesn't exist, and needs noGITHUB_TOKENpermissions.deleteworkflows run from the default branch, so this takes effect for branches deleted after it is merged. Previews of branches deleted earlier can be removed in the Cloudflare dashboard.