Repository navigation
Description
Context
The org is migrating lecture PR previews from Netlify to Cloudflare
(QuantEcon/infrastructure#4). Cloudflare's investment has moved from Pages
to Workers static assets (Pages is maintenance mode; Workers reached
static-asset feature parity in 2026), and Workers now supports the one
mechanism our design depends on: deterministic, stable per-PR preview
aliases via wrangler versions upload --preview-alias pr-N
(Wrangler ≥ 4.21.0), yielding:
https://pr-{N}-{worker-name}.{account-subdomain}.workers.dev
Since no repo has cut over yet, we target Workers directly rather than
migrating the fleet through Pages. preview-cloudflare (Pages, v0.11.1)
stays as released fallback.
Proposed change
Either a platform: input on preview-cloudflare (pages | workers,
default workers) or a sibling preview-workers action — maintainer's
choice; the shared change-detection and comment machinery is identical
either way (aligns with PLAN item 6, shared comment-script extraction).
Deploy-step differences from the Pages path:
wrangler pages deploy $BUILD_DIR --project-name=X --branch=pr-N
→wrangler versions upload --preview-alias pr-N
(assets dir + worker name come from a minimalwrangler.toml/.jsonc
with[assets] directoryandpreview_urls = true, generated by the
action or committed per repo — decide below)versions uploadnever touches production traffic — no accidental
"deploy" concept for preview-only workers- Alias URL is CONSTRUCTED, not parsed (same fix(preview-cloudflare): link the stable pr-N alias, not the deployment hash (#14) #131 discipline). New
required input:account-subdomain(workers.dev subdomain). The
official wrangler-action doesn't expose the aliased URL in outputs, so
construction remains the right call. - Alias-safety: reuse the existing lowercase/dash mapping;
pr-Nalready
conforms
Design decisions
-
platform:input vs sibling action - wrangler config: generated ephemerally by the action (keeps consumer
repos config-free, like today) vs committed per repo - Pin wrangler ≥ 4.21.0 (also update the pinned CLI baked into the
quantecon-previewimage / GPU AMI per PROJECT-OPTIMIZE-PREVIEWS —
wrangler, not netlify-cli) - Outputs: keep
deploy-url(stable alias) +deployment-url
(per-version hash URL) semantics identical to the Pages action
Verify during pilot (lecture-dp)
- Static asset file-count and 25 MiB limits per Worker version
against the largest repos'_build/html(unclear whether Workers
got the 100k paid bump Pages received Jan 2026) - Version retention: how long old versions + aliased URLs persist;
pruning mechanism (differs from Pages deployments) - Alias stability across many pushes to one PR; behaviour when two
uploads race (concurrency-cancellation from Optimize preview builds: phased plan for the fastest PR previews (tracking) #92 Phase 1 should land
first) - Fork/dependabot trust gate carries over unchanged
- Optional: Cloudflare Access in front of preview URLs (works on
workers.dev previews) for any repo needing gated drafts
Out of scope
- Production publishing (stays on GH Pages)
preview-netlifyremoval (tracked in QuantEcon/infrastructure#4 decommission)
Refs
- QuantEcon/infrastructure#4 (org migration project) · Optimize preview builds: phased plan for the fastest PR previews (tracking) #92 (preview optimization) ·
fix(preview): surface deploy errors, pin CLIs, remove unsafe fork guidance #105 (pipefail in wrangler output capture — fix before rollout) ·
fix(preview-cloudflare): link the stable pr-N alias, not the deployment hash (#14) #131 (constructed alias URL) · PLAN items 5/6
Activity
mmcky commentedon Nov 5, 2026
Carried over from #153, which is now closed. #153 noted that the placeholder comment should give the Workers alias URL template once QuantEcon/infrastructure#4 lands. Both halves of #153 are on
mainand unreleased: the shared comment scriptscripts/preview-comment.cjs(#253), and the placeholder comment,placeholder: 'true'on both preview actions (#258). So the Workers path here can reuse both. It needs a provider entry in the shared script, and a deterministic placeholder URL for the Workers alias.Claude Code (on behalf of mmcky), organiser session
mmcky commentedon Nov 6, 2026
Checked against
mainat9644f17(2026-11-06). Most of this issue's design has been settled since it was filed, by code already onmain.deploy-cloudflare(#176) generates its wrangler config per run (write-config.js, withassets.directoryandpreview_urls: true, dry-run in the harness), builds its URLs from anaccount-subdomaininput, validates aliases by Cloudflare's rules (a leading letter, and<alias>-<worker>within 63 characters), and already runswrangler versions upload --preview-alias. Wrangler is pinned at 4.156.1 by lockfile, well past 4.21.0. The trust gate, the comment and the placeholder are shared scripts:preview-decide.sh(#240),preview-comment.cjs(#253) andplaceholder(#258). #105 is closed. Baking wrangler into aquantecon-previewimage is moot, since the actions install their CLI from a lockfile on every run.The maintainer has decided the shape (2026-11-07): a sibling action,
preview-workers, not aplatform:input onpreview-cloudflare. Aworkersdefault for that input would break every current caller, since the inputs differ (worker-nameandaccount-subdomainagainstproject-name), and with apagesdefault every input would depend on another. The sibling has a clean input set and the same outputs as the other two preview actions (deployed,deploy-url,deployment-url,changed-files). It is mostly calls to the shared scripts plusdeploy-cloudflare's config writer, moved toscripts/.preview-comment.cjsneeds aworkersprovider whose site is<worker>.<subdomain>.And the timing: it is built in a later wave, once the maintainer has a Worker and a token on the canary. A pull request's harness can't deploy, so the action's first real deploy has to happen on the canary before its staged release, and an org-owned Cloudflare account isn't set up yet. The pilot's checks (limits per version, retention, alias races, Access in front of previews) stay with the preview-platform decision, outside this repository.
Claude Code (on behalf of mmcky)
mmcky commentedon Nov 10, 2026
Checked again against
mainat0f4ee09(2026-11-10), for the build. The maintainer's decision of 2026-11-07 stands: a siblingpreview-workersaction. What has changed since the last check: the canary now has a Worker on the org's Cloudflare account,qe-preview-canary, with an account-owned token scoped to that one Worker, so the earlier "no org account yet" no longer holds. And #281 (#216) madepreview-cloudflareread its URL from wrangler's record of the deploy, which this action follows.The design:
preview-workersrunswrangler versions upload --preview-alias pr-<number>, which uploads a new version of an existing Worker without changing what it serves in production. It serves the preview athttps://pr-<number>-<worker-name>.<account-subdomain>.workers.dev, confirmed on the canary's Worker. It reusespreview-decide.sh, change detection,preview-comment.cjs(with a newworkersprovider, whose placeholder URL is built from the same two inputs) anddeploy-cloudflare's config writer, moved toscripts/with no change todeploy-cloudflare. Its inputs arecloudflare-api-token,cloudflare-account-id,worker-name,account-subdomain,build-dir,lectures-dir,dispatch-aliasandplaceholder, and its outputs are the other preview actions' four.The pinned wrangler (4.156.1) writes a
version-uploadrecord of each upload that names the version's preview URL and the alias's URL, both taken from Cloudflare. The action buildsdeploy-urlfrom its inputs and checks it against that record. A mismatch means a wrongaccount-subdomain, and no alias URL means the Worker's preview URLs are off, whichversions uploaddoes not turn on. Both fail the job, rather than post a link that cannot load. With no record at all, it warns and falls back, as #216 does.deployment-urlis the version's own preview URL. A dry run writes the record too, so the harness can catch a wrangler bump that drops it, with no account.A pull request's harness has no Cloudflare secrets, so the harness covers the inputs, the trust gate, the config through the pinned wrangler, the comment and the placeholder, and the URL check against a recorded wrangler record. The first real upload runs on the canary before the PR merges, and again at the staged release. That run covers the placeholder then the deploy in one comment, a second push on the same alias, a dispatch alias, a wrong subdomain failing, and production left untouched. The pilot's checks (per-version file and size limits, version retention, alias races, Access in front of previews) move to their own issue for the first lecture repository that adopts the action.
The maintainer's decisions, 2026-11-10, taken one at a time, each as recommended:
build-dirare needed for a deploy but not marked required, so the placeholder job holds no secrets. There is novisibilityinput for now; the examples name the secretCLOUDFLARE_WORKERS_TOKEN;https://<alias>-<worker-name>.<account-subdomain>.workers.dev, in a comment with its own marker and heading;deploy-cloudflare's writer moves toscripts/write-wrangler-config.js.Claude Code (on behalf of mmcky), organiser session; the check by the mini:actions-workers session
test(preview-workers): the stub writes the record from the canary's f…
feat(preview-workers): preview a pull request on a Cloudflare Worker (#…