Skip to content

Commit 520685f

Browse files
authored
Merge branch 'main' into lduarte/fix-multiple-workflows-miniflare
2 parents 9371733 + 09e6e90 commit 520685f

File tree

8 files changed

+57
-17
lines changed

8 files changed

+57
-17
lines changed

.changeset/mighty-beds-grab.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Include Version Preview URL in Wrangler's output file

.changeset/shy-seas-wave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
chore(wrangler): update unenv dependency version

packages/wrangler/e2e/versions.test.ts

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { readFile } from "fs/promises";
2+
import path from "path";
13
import dedent from "ts-dedent";
2-
import { describe, expect, it } from "vitest";
4+
import { beforeAll, describe, expect, it } from "vitest";
35
import { CLOUDFLARE_ACCOUNT_ID } from "./helpers/account-id";
46
import { WranglerE2ETestHelper } from "./helpers/e2e-wrangler-test";
57
import { generateResourceName } from "./helpers/generate-resource-name";
@@ -23,9 +25,10 @@ describe("versions deploy", { timeout: TIMEOUT }, () => {
2325
let versionId0: string;
2426
let versionId1: string;
2527
let versionId2: string;
26-
const helper = new WranglerE2ETestHelper();
28+
let helper: WranglerE2ETestHelper;
2729

28-
it("deploy worker", async () => {
30+
beforeAll(async () => {
31+
helper = new WranglerE2ETestHelper();
2932
await helper.seed({
3033
"wrangler.toml": dedent`
3134
name = "${workerName}"
@@ -632,6 +635,27 @@ describe("versions deploy", { timeout: TIMEOUT }, () => {
632635
`);
633636
});
634637

638+
it("should include version preview url in output file", async () => {
639+
const outputFile = path.join(helper.tmpPath, "output.jsonnd");
640+
const upload = await helper.run(
641+
`wrangler versions upload --message "Upload via e2e test" --tag "e2e-upload" --x-versions`,
642+
{
643+
env: {
644+
...process.env,
645+
WRANGLER_OUTPUT_FILE_PATH: outputFile,
646+
},
647+
}
648+
);
649+
650+
versionId1 = matchVersionId(upload.stdout);
651+
652+
const output = await readFile(outputFile, "utf8");
653+
654+
expect(JSON.parse(normalizeOutput(output.split("\n")[1]))).toMatchObject({
655+
preview_url: "https://tmp-e2e-worker-PREVIEW-URL.SUBDOMAIN.workers.dev",
656+
});
657+
});
658+
635659
it("should delete Worker", async () => {
636660
const { stdout } = await helper.run(`wrangler delete`);
637661

packages/wrangler/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"resolve.exports": "^2.0.2",
8686
"selfsigned": "^2.0.1",
8787
"source-map": "^0.6.1",
88-
"unenv": "npm:[email protected]20241024-111401-d4156ac",
88+
"unenv": "npm:[email protected]20241111-080453-894aa31",
8989
"workerd": "1.20241106.1",
9090
"xxhash-wasm": "^1.0.1"
9191
},

packages/wrangler/src/output.ts

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ interface OutputEntryVersionUpload extends OutputEntryBase<"version-upload"> {
128128
worker_tag: string | null;
129129
/** A GUID that identifies this uploaded, but not yet deployed, version of the Worker. This version will need to be "deployed" to receive traffic. */
130130
version_id: string | null;
131+
/** The preview URL associated with this version upload */
132+
preview_url: string | undefined;
131133
}
132134

133135
interface OutputEntryVersionDeployment

packages/wrangler/src/versions/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ async function versionsUploadHandler(
274274
if (!args.dryRun) {
275275
await standardPricingWarning(config);
276276
}
277-
const { versionId, workerTag } = await versionsUpload({
277+
const { versionId, workerTag, versionPreviewUrl } = await versionsUpload({
278278
config,
279279
accountId,
280280
name,
@@ -313,6 +313,7 @@ async function versionsUploadHandler(
313313
worker_name: name ?? null,
314314
worker_tag: workerTag,
315315
version_id: versionId,
316+
preview_url: versionPreviewUrl,
316317
});
317318
}
318319

packages/wrangler/src/versions/upload.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ function errIsStartupErr(err: unknown): err is ParseError & { code: 10021 } {
112112
return false;
113113
}
114114

115-
export default async function versionsUpload(
116-
props: Props
117-
): Promise<{ versionId: string | null; workerTag: string | null }> {
115+
export default async function versionsUpload(props: Props): Promise<{
116+
versionId: string | null;
117+
workerTag: string | null;
118+
versionPreviewUrl?: string | undefined;
119+
}> {
118120
// TODO: warn if git/hg has uncommitted changes
119121
const { config, accountId, name } = props;
120122
let versionId: string | null = null;
@@ -565,6 +567,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
565567
logger.log("Uploaded", workerName, formatTime(uploadMs));
566568
logger.log("Worker Version ID:", versionId);
567569

570+
let versionPreviewUrl: string | undefined = undefined;
571+
568572
if (versionId && hasPreview) {
569573
const { enabled: available_on_subdomain } = await fetchResult<{
570574
enabled: boolean;
@@ -573,9 +577,8 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
573577
if (available_on_subdomain) {
574578
const userSubdomain = await getWorkersDevSubdomain(accountId);
575579
const shortVersion = versionId.slice(0, 8);
576-
logger.log(
577-
`Version Preview URL: https://${shortVersion}-${workerName}.${userSubdomain}.workers.dev`
578-
);
580+
versionPreviewUrl = `https://${shortVersion}-${workerName}.${userSubdomain}.workers.dev`;
581+
logger.log(`Version Preview URL: ${versionPreviewUrl}`);
579582
}
580583
}
581584

@@ -591,7 +594,7 @@ Changes to triggers (routes, custom domains, cron schedules, etc) must be applie
591594
`)
592595
);
593596

594-
return { versionId, workerTag };
597+
return { versionId, workerTag, versionPreviewUrl };
595598
}
596599

597600
function helpIfErrorIsSizeOrScriptStartup(

pnpm-lock.yaml

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)