Skip to content

Commit f3184d9

Browse files
committed
fix(publish): improve cloudflare publish resilience
1 parent ae3308d commit f3184d9

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

src/publish/cloudflare/cloudflare.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { renderForPublish } from "../common/publish.ts";
1616
import { RenderFlags } from "../../command/render/types.ts";
1717
import { execProcess } from "../../core/process.ts";
1818
import { anonymousAccount } from "../common/git.ts";
19+
import { sleep } from "../../core/wait.ts";
1920

2021
export const kCloudflarePages = "cloudflare-pages";
2122
const kCloudflarePagesDescription = "Cloudflare Pages";
@@ -146,6 +147,9 @@ type WranglerDeployment = {
146147
branch?: string;
147148
};
148149

150+
const kDeploymentLookupRetries = 3;
151+
const kDeploymentLookupDelay = 500;
152+
149153
async function ensureProjectExists(projectName: string) {
150154
const result = await execWrangler([
151155
"pages",
@@ -160,13 +164,28 @@ async function ensureProjectExists(projectName: string) {
160164
});
161165
if (!result.success) {
162166
throw new Error(
163-
`Unable to access Cloudflare Pages project '${projectName}'. Create it first with 'wrangler pages project create ${projectName}' or run without --no-prompt.`,
167+
`Unable to access Cloudflare Pages project '${projectName}'. Ensure Wrangler is authenticated (wrangler login or CLOUDFLARE_ACCOUNT_ID/CLOUDFLARE_API_TOKEN) and the project exists. Create it first with 'wrangler pages project create ${projectName} --production-branch <branch>' or run without --no-prompt.`,
164168
);
165169
}
166170
}
167171

168172
async function deploymentUrlFromWrangler(
169173
projectName: string,
174+
): Promise<string | undefined> {
175+
for (let attempt = 0; attempt < kDeploymentLookupRetries; attempt++) {
176+
const url = await tryDeploymentUrlFromWrangler(projectName);
177+
if (url) {
178+
return url;
179+
}
180+
if (attempt < kDeploymentLookupRetries - 1) {
181+
await sleep(kDeploymentLookupDelay);
182+
}
183+
}
184+
return undefined;
185+
}
186+
187+
async function tryDeploymentUrlFromWrangler(
188+
projectName: string,
170189
): Promise<string | undefined> {
171190
try {
172191
const result = await execWrangler([

0 commit comments

Comments
 (0)