Skip to content

Commit c7dbcd1

Browse files
ianmacartneyConvex, Inc.
authored andcommitted
Add Cloudflare Pages automatic preview deploy detection (#49823)
Addresses get-convex/convex-backend#440 Adds automatic Cloudflare Pages preview deployment detection to `convex deploy`, matching the existing Vercel/Netlify behavior. When `CF_PAGES` is set, the CLI now uses `CF_PAGES_BRANCH` as the preview deployment name and detects non-production builds via a branch name heuristic. GitOrigin-RevId: f7a1ff7c4c9770630309c7ee299162141bfffec5
1 parent 8a9caea commit c7dbcd1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/cli/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const deploy = new Command("deploy")
4949
.addOption(
5050
new Option(
5151
"--preview-create <name>",
52-
"The name to associate with this deployment if deploying to a newly created preview deployment. Defaults to the current Git branch name in Vercel, Netlify and GitHub CI. This parameter can only be used with a preview deploy key (when used with another type of key, the command will return an error).",
52+
"The name to associate with this deployment if deploying to a newly created preview deployment. Defaults to the current Git branch name in Vercel, Netlify, Cloudflare Pages and GitHub CI. This parameter can only be used with a preview deploy key (when used with another type of key, the command will return an error).",
5353
).conflicts("preview-name"),
5454
)
5555
.addOption(

src/cli/lib/envvars.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,9 @@ export function getBuildEnvironment(): string | false {
433433
? "Vercel"
434434
: process.env.NETLIFY
435435
? "Netlify"
436-
: false;
436+
: process.env.CF_PAGES || process.env.WORKERS_CI
437+
? "Cloudflare"
438+
: false;
437439
}
438440

439441
export function gitBranchFromEnvironment(): string | null {
@@ -445,6 +447,11 @@ export function gitBranchFromEnvironment(): string | null {
445447
// https://docs.netlify.com/configure-builds/environment-variables/
446448
return process.env.HEAD ?? null;
447449
}
450+
if (process.env.CF_PAGES || process.env.WORKERS_CI) {
451+
// https://developers.cloudflare.com/pages/configuration/build-configuration/#environment-variables
452+
// https://developers.cloudflare.com/workers/ci-cd/builds/configuration/#environment-variables
453+
return process.env.CF_PAGES_BRANCH ?? process.env.WORKERS_CI_BRANCH ?? null;
454+
}
448455

449456
if (process.env.CI) {
450457
// https://docs.github.com/en/actions/learn-github-actions/variables
@@ -466,5 +473,13 @@ export function isNonProdBuildEnvironment(): boolean {
466473
// https://docs.netlify.com/configure-builds/environment-variables/
467474
return process.env.CONTEXT !== "production";
468475
}
476+
if (process.env.CF_PAGES || process.env.WORKERS_CI) {
477+
// https://developers.cloudflare.com/pages/configuration/build-configuration/#environment-variables
478+
// https://developers.cloudflare.com/workers/ci-cd/builds/configuration/#environment-variables
479+
// Branch !== "main" is the closest heuristic; Cloudflare Pages
480+
// does not expose a dedicated production/preview flag.
481+
const branch = process.env.CF_PAGES_BRANCH ?? process.env.WORKERS_CI_BRANCH;
482+
return branch !== "main";
483+
}
469484
return false;
470485
}

0 commit comments

Comments
 (0)