Pull requests
Every pull request gets a live copy of the site, linked in a comment, and the copy disappears when the pull request closes. All in deploy.yml.
A preview per pull request
wrangler preview --name pr-<N> uploads the site as a
Workers Preview
at https://pr-<N>-<worker>.<account>.workers.dev, updated on
every push. Each push also gets its own version URL, so the state of any commit stays
reachable. Production is untouched until the merge.
It needs "previews": {} in wrangler.jsonc. If the Worker does
not exist yet, the first preview creates it, without a route, so pull requests work even
before the first production deploy.
The preview comment
Each deploy posts a new comment, titled with its commit, with a table:
| Row | What it holds |
|---|---|
| Preview | The pull request's preview URL |
| This commit | The version URL of exactly this commit |
| Deploy log | The workflow run: build, deploy, visual, Lighthouse |
| Preview on mobile | A collapsible QR code of the preview URL |
| Lighthouse | Scores of the preview's home page, filled in by the lighthouse job |
The earlier preview comments are then collapsed as outdated (GitHub's
minimizeComment), so the conversation stays short while every old comment keeps
its links and scores one click away. Comments are found by the hidden marker
<!-- preview-links --> they start with. The workflow's own
GITHUB_TOKEN is enough; no extra app or token.
QR code
GitHub comments cannot embed an image inline, so the QR code is a PNG published inside the
preview itself, at /pr-preview-qr.png; it never reaches production. That needs the
preview URL before the upload: it is predicted from the Worker name and the account's
workers.dev subdomain (WORKERS_SUBDOMAIN), and checked against what wrangler
reports afterwards. If they differ, the QR code is redone and the preview uploaded once more,
with a warning to fix the setting. Black on white, so it also scans in GitHub's dark mode.
Cleanup
When the pull request is closed or merged, wrangler preview delete removes the
preview, the preview comments are collapsed (their links are dead now) and a short new
comment says so. Reopening the pull request starts over with a fresh preview.
Forks and Dependabot
Pull requests from forks and from Dependabot run without the repository's secrets, so they cannot be previewed. Fork pull requests skip the deploy job; Dependabot's run it but skip the preview and everything that needs one, instead of failing. The link checker still runs on both.
One run at a time
Runs are grouped per pull request (and one group for production) without cancelling: a new push waits for the previous run, and closing a pull request waits for a running deploy, so the cleanup never races a preview upload.