Skip to content

Add Workers static assets support to the Cloudflare preview action #145

Closed

Description

@mmcky

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 minimal wrangler.toml/.jsonc
    with [assets] directory and preview_urls = true, generated by the
    action or committed per repo — decide below)
  • versions upload never 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-N already
    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-preview image / 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-netlify removal (tracked in QuantEcon/infrastructure#4 decommission)

Refs

Activity

  1. added
    enhancement
    on Aug 13, 2026
  2. mmcky commented on Nov 5, 2026

    @mmcky
    ContributorAuthor

    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 main and unreleased: the shared comment script scripts/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

  3. mmcky commented on Nov 6, 2026

    @mmcky
    ContributorAuthor

    Checked against main at 9644f17 (2026-11-06). Most of this issue's design has been settled since it was filed, by code already on main. deploy-cloudflare (#176) generates its wrangler config per run (write-config.js, with assets.directory and preview_urls: true, dry-run in the harness), builds its URLs from an account-subdomain input, validates aliases by Cloudflare's rules (a leading letter, and <alias>-<worker> within 63 characters), and already runs wrangler 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) and placeholder (#258). #105 is closed. Baking wrangler into a quantecon-preview image 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 a platform: input on preview-cloudflare. A workers default for that input would break every current caller, since the inputs differ (worker-name and account-subdomain against project-name), and with a pages default 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 plus deploy-cloudflare's config writer, moved to scripts/. preview-comment.cjs needs a workers provider 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)

  4. mmcky commented on Nov 10, 2026

    @mmcky
    ContributorAuthor

    Checked again against main at 0f4ee09 (2026-11-10), for the build. The maintainer's decision of 2026-11-07 stands: a sibling preview-workers action. 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) made preview-cloudflare read its URL from wrangler's record of the deploy, which this action follows.

    The design: preview-workers runs wrangler 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 at https://pr-<number>-<worker-name>.<account-subdomain>.workers.dev, confirmed on the canary's Worker. It reuses preview-decide.sh, change detection, preview-comment.cjs (with a new workers provider, whose placeholder URL is built from the same two inputs) and deploy-cloudflare's config writer, moved to scripts/ with no change to deploy-cloudflare. Its inputs are cloudflare-api-token, cloudflare-account-id, worker-name, account-subdomain, build-dir, lectures-dir, dispatch-alias and placeholder, and its outputs are the other preview actions' four.

    The pinned wrangler (4.156.1) writes a version-upload record of each upload that names the version's preview URL and the alias's URL, both taken from Cloudflare. The action builds deploy-url from its inputs and checks it against that record. A mismatch means a wrong account-subdomain, and no alias URL means the Worker's preview URLs are off, which versions upload does 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-url is 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:

    • the eight inputs above. The token, account ID and build-dir are needed for a deploy but not marked required, so the placeholder job holds no secrets. There is no visibility input for now; the examples name the secret CLOUDFLARE_WORKERS_TOKEN;
    • the placeholder links to https://<alias>-<worker-name>.<account-subdomain>.workers.dev, in a comment with its own marker and heading;
    • the job fails when wrangler's record disagrees with the built URL or has no alias URL, and only warns and falls back when there is no record;
    • the PR closes this issue, and the pilot's checks go to a new issue. deploy-cloudflare's writer moves to scripts/write-wrangler-config.js.

    Claude Code (on behalf of mmcky), organiser session; the check by the mini:actions-workers session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions