Preview every pull request at /pr-preview/pr-<number>/ - #34
Merged
Merged
Conversation
A change to the site could only be seen by building it locally or merging it live. Each PR now gets the built site at bendichter.com/pr-preview/pr-<number>/, linked from a comment on the PR, rebuilt on every push and removed when the PR closes. GitHub Pages serves one site per repo, so previews live on the gh-pages branch beside the live site. That means production moves from an artifact deploy, which replaces the whole site and would delete every open preview, to pushing dist to gh-pages with pr-preview/ excluded from the clean. public/.nojekyll comes along so Pages serves the output as-is; Jekyll would drop _astro/ and .well-known/. A preview is the production build, strict checks included, with its root-relative links rewritten afterwards by scripts/rebase-preview.mjs. Astro's `base` would only cover the URLs Astro generates, not the hand-written ones in templates and markdown. The script fails if any link would still lead out of the preview to the live site. robots.txt keeps /pr-preview/ out of search, and canonical URLs stay pointed at the live pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 changes
Each PR gets the built site at
https://bendichter.com/pr-preview/pr-<number>/, linked from a comment on the PR. The preview is rebuilt on every push and removed when the PR closes..github/workflows/preview.yml(new): runs on PR open/push/close. It builds the site with the samenpm run buildas production (strict checks included), re-roots it under the preview path, and publishes it withrossjrw/pr-preview-action..github/workflows/deploy.yml: production now pushesdistto thegh-pagesbranch (JamesIves/github-pages-deploy-action) withclean-exclude: pr-preview/. The previous artifact deploy replaced the whole site, so it would delete every open preview on each deploy.scripts/rebase-preview.mjs(new): rewrites root-relative URLs in the built HTML and the web manifest to the preview path:href,src,srcset, and the meta-refresh redirect pages. It fails the run if any root-relative link would still lead out of the preview to the live site. It works on the output rather than through Astro'sbase, which only covers URLs Astro generates, not the hand-written ones in templates and markdown.public/.nojekyll: branch-served Pages runs Jekyll unless told not to, and Jekyll drops_astro/(all CSS and images) and.well-known/(the Bluesky handle verification).robots.txt: disallows/pr-preview/. Canonical URLs on preview pages already point at the live site.Tested locally
I built the site, re-rooted it under
/pr-preview/pr-99/, served it from a parent directory, and crawled every internal link from the preview homepage. 114 pages and assets resolved, none broken, and none led back to the live site. A screenshot of the preview homepage showed styles, images, and the avatar all loading. actionlint passes on both workflows.GitHub Pages is currently set to deploy from GitHub Actions. After this merges and the first production deploy has pushed
gh-pages, switch Settings → Pages → Source to Deploy from a branch →gh-pages/ root. Or run:Until then, the live site keeps serving its last deploy unchanged, and previews are pushed to
gh-pagesbut not served. The custom domain comes along viaCNAMEin the build.🤖 Generated with Claude Code