Skip to content

fix(cloudflare): default to worker, optional account id, infer prod branch#846

Merged
BYK merged 2 commits into
masterfrom
fix/cloudflare-target-review
Jul 21, 2026
Merged

fix(cloudflare): default to worker, optional account id, infer prod branch#846
BYK merged 2 commits into
masterfrom
fix/cloudflare-target-review

Conversation

@BYK

@BYK BYK commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #843 addressing the review comments left on the cloudflare docs. Three behavior changes + docs/tests.

1. Default deployType: worker (was pages)

Cloudflare is steering new projects to Workers (with static assets) and positioning Pages as legacy, so worker is the forward-looking default. Pages remains fully supported via deployType: pages.

2. CLOUDFLARE_ACCOUNT_ID is now optional (not a secret)

The account ID is an identifier, not a credential. Only CLOUDFLARE_API_TOKEN is a required secret now. The account ID is read from the environment and forwarded to wrangler only when set; otherwise wrangler auto-discovers it for single-account tokens (confirmed against wrangler v4 behavior).

3. productionBranch auto-inferred for Pages

wrangler pages deploy --branch <X> deploys to production only when <X> exactly matches the project's server-side production branch — any other value silently produces a preview deploy. Previously we defaulted to main, which is a guess. Now:

  1. If productionBranch is configured → used verbatim.
  2. Else, if the account ID is known → read the project's production_branch from GET /accounts/{id}/pages/projects/{name} (the same call wrangler makes internally, so no extra token scope — Pages:Edit covers it).
  3. Else → omit --branch (a bare deploy from the non-git temp dir defaults to production).

A 404 (wrong project/account) fails loudly rather than masking a misconfig; transient/network errors fall back to omitting --branch.

Safety

  • Dry-run makes zero network calls: the isDryRun() guard runs before both the inference fetch() and spawnProcess.
  • No token leakage: token is env-only (never argv), and error messages don't carry it.
  • Defense-in-depth: API-sourced branch values are also checked against the ${VAR} env-expansion guard before reaching argv.
  • No new dependency — raw global fetch (Node 24.18.0 baseline).

Testing

  • pnpm test — full suite green (1052 passed). 27 cloudflare tests covering: worker default, account-id optional/forwarded-when-set, branch inference (correct URL + Bearer auth header), config-branch-skips-API, 404 hard-fail, API-failure/no-account-id fallbacks, suspicious-branch guard, worker-never-calls-API, and dry-run-makes-no-fetch.
  • tsc / pnpm lint clean. Docs build clean.

Review

Adversarial subagent review: dry-run zero-network-call invariant verified by code walk; no token leak; no CRITICAL/MAJOR issues. Findings MINOR-1 (guard the API-sourced branch) and MINOR-3 (hard-fail on 404) were addressed in this PR.

Addresses review comments on #843 (productionBranch default, account-id-not-a-secret, auto-discovery/inference).

🤖 Generated with opencode

…ranch

Addresses review feedback on the cloudflare target (#843):

- Default `deployType` is now `worker` (was `pages`). Cloudflare is
  steering new projects to Workers with static assets and positioning
  Pages as legacy, so Workers is the forward-looking default. Pages is
  still fully supported via `deployType: pages`.
- `CLOUDFLARE_ACCOUNT_ID` is no longer treated as a required secret --
  it is an identifier, not a credential. Only `CLOUDFLARE_API_TOKEN`
  remains a required secret. The account id is forwarded to wrangler
  only when set; otherwise wrangler auto-discovers it for single-account
  tokens.
- `productionBranch` is now optional and auto-inferred for Pages. When
  unset, the target reads the project's production branch from the
  Cloudflare API (`GET /accounts/{id}/pages/projects/{name}`, the same
  call wrangler makes internally -- no extra token scope) and passes it
  as `--branch` so the release reliably lands on production instead of a
  silent preview. A 404 (wrong project/account) fails loudly; transient
  errors fall back to omitting `--branch` (a bare non-git deploy defaults
  to production).

The dry-run guard runs before any network call, so a dry run still makes
zero remote calls. API-sourced branch values are also checked against the
`${VAR}` env-expansion guard as defense-in-depth. Docs updated to lead
with worker, describe the branch-inference flow, mark the account id
optional, and note there is no OIDC option for Cloudflare.
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-07-21 10:53 UTC

Comment thread src/targets/cloudflare.ts
@BYK
BYK merged commit 83964a8 into master Jul 21, 2026
24 checks passed
@BYK
BYK deleted the fix/cloudflare-target-review branch July 21, 2026 10:53
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