Repository navigation
Add Pull Request Previews - #1169
Merged
Merged
Conversation
Reuse the web build from pull request CI to publish previews to Cloudflare Pages. Give each pull request a stable branch URL and link it from a Web preview check on the tested commit. Keep the hosting account and project configurable so the same workflows also work in forks. Separate building from publishing so pull request code never receives the deployment token. Resolve the pull request and artifact through GitHub's API, publish only the current open head after successful CI, and execute the publisher from the default branch. Validate the static files and run Wrangler in an isolated directory to prevent uploaded Workers, package scripts, or configuration from running with deployment credentials. Use native TypeScript helpers and include them in linting and type checking. Build optimized previews with the usual WebAssembly and font preloading, but leave out the production service worker so updates appear immediately. Allow previews to build when contributor credits cannot be fetched. Keep each pull request on its own origin so its saved splits and layouts remain separate from production and other previews while surviving preview updates. Delete every deployment for a pull request when it closes or merges, including older builds and the branch alias. Gather all deployment pages before deleting, protect production and other pull requests, and retire the preview check after cleanup. Serialize publishing and cleanup for each pull request, recheck its current state, and handle closed pull requests before downloading artifacts so a late publisher can still clean up after an expired artifact or a replaced pending close job.
Post a direct preview link in the pull request conversation after a successful upload, alongside the Web preview check. Reviewers can open the running build from the pull request itself without visiting Actions. Update the same bot-owned comment for subsequent builds so the link stays current without posting another notification on every update. Mark that comment as removed when the pull request closes or merges, and avoid posting removal comments for pull requests that never had a preview. Grant pull request write access only to the trusted publishing and cleanup jobs that maintain this comment. Match both the bot identity and the preview marker before editing so other conversation comments stay intact.
CryZe
marked this pull request as ready for review
October 12, 2026 20:22
CryZe
enabled auto-merge
October 12, 2026 20:22
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.
Web changes currently require a local build to review in the browser. Reuse the existing GitHub Actions web build to publish a Cloudflare Pages preview for each pull request after CI succeeds, with a stable
pr-N.<project>.pages.devaddress. A bot comment on the PR's Conversation page provides an Open preview link as soon as the upload succeeds; the Web preview check also links directly to it. Later builds update the same comment instead of posting another notification.Each pull request has its own browser origin, so preview splits and layouts are isolated from production and other previews while remaining available across updates to the same PR. Previews use the optimized frontend and WebAssembly/font preloading, omit the production service worker to avoid stale builds, and can still build when GitHub contributor credits are unavailable.
flowchart LR PR[Open or update PR] --> CI[Existing CI build] CI --> Upload[Trusted preview publisher] Upload --> Preview[Stable URL for this PR] Preview --> Comment[PR conversation with Open preview link] Closed[Close or merge PR] --> Cleanup[Delete all builds for this PR]Publishing runs trusted default-branch TypeScript helpers after the build, so PR code never receives the Cloudflare token. GitHub API metadata identifies the current open PR and its artifact; static-file validation and an isolated Wrangler directory prevent artifact-supplied executable code or configuration from running with deployment credentials.
Closing or merging a PR deletes all of its preview deployments, including older builds and the branch alias, retires its preview check, and updates its existing comment to say that the preview was removed. Publishing and cleanup share a per-PR concurrency group. Late publishers handle closed PRs before downloading artifacts, covering both expired artifacts and GitHub replacing a pending close job. Production deployments, other PRs, and unrelated conversation comments remain protected.
Configure repository variables
CLOUDFLARE_ACCOUNT_IDandCLOUDFLARE_PAGES_PROJECT, plus the repository secretCLOUDFLARE_API_TOKENwith Pages read/write access. Hosting uses Cloudflare Pages Direct Upload on the free plan. The publisher starts once these workflows are on the default branch; until then, CI produces a downloadable preview artifact.