ci: PR-event-driven deploys with automatic preview cleanup#7
Merged
Conversation
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
Rebuild
.github/workflows/cicd.ymlaround the pull-request lifecycle. Preview subdomains are now created when a PR opens, updated on every push, and torn down when the PR closes or merges. Pushes to non-main branches no longer spawn subdomains on their own.Why
The old workflow had no cleanup path: every push to any branch created (or silently re-created) a
{branch}.lef.fyipreview, and nothing ever removed them. Over time this left orphaned S3 buckets and Cloudflare CNAMEs behind. Tying the preview lifecycle to PR events closes that loop and stops new drift.How
Two jobs, both in the same file, gated by
if:on the event type:deploy— runs forpushtomainorpull_requestopened/synchronize/reopened. Creates the bucket if needed, syncssrc/, and upserts the CNAME (query → PUT existing or POST new) so repeated runs no longer silently fail on duplicate DNS.cleanup— runs forpull_requestclosed(merged or not). Empties + deletes the preview bucket and removes the CNAME. Best-effort: both steps check for existence first and skip if already gone.Other changes:
on: pushis now restricted tobranches: [main]. Pushes to other branches no longer deploy anything by themselves — open a PR if you want a preview.deploy-${PR_NUMBER || ref}withcancel-in-progress: falseso a deploy and its matching cleanup serialize instead of racing on the same bucket.head.repo.full_name == github.repository), since secrets are unavailable to fork PRs anyway.Not handled in this PR
Existing orphaned previews from before this change (
claude-scaffold,gatsby-init,hugo,this-is-cool, plusci-pr-previewsfrom this very push) still need a one-time manual cleanup. Going forward, the new workflow will keep the house in order.Test plan
cleanupjob fires on theclosedevent and tears downci-pr-previews.lef.fyi(if GitHub runs the new workflow from main at close time).src/**change to confirm the preview subdomain appears on the opened event.