Skip to content

Preview every pull request at /pr-preview/pr-<number>/ - #34

Merged
bendichter merged 1 commit into
masterfrom
claude/pr-previews
Sep 26, 2026
Merged

bendichter merged 1 commit into
masterfrom
claude/pr-previews

Conversation

@bendichter

Copy link
Copy Markdown
Owner

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 same npm run build as production (strict checks included), re-roots it under the preview path, and publishes it with rossjrw/pr-preview-action.
  • .github/workflows/deploy.yml: production now pushes dist to the gh-pages branch (JamesIves/github-pages-deploy-action) with clean-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's base, 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.
  • README and PRODUCT.md describe the new setup.

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.

⚠️ One settings change after merging

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:

gh api -X PUT repos/bendichter/bendichter.github.io/pages \
  -f build_type=legacy -f 'source[branch]=gh-pages' -f 'source[path]=/'

Until then, the live site keeps serving its last deploy unchanged, and previews are pushed to gh-pages but not served. The custom domain comes along via CNAME in the build.

🤖 Generated with Claude Code

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>
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-09-26 13:59 UTC

@bendichter
bendichter merged commit 974cbb5 into master Sep 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant