Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deployment HTTP targets to wrangler deploy output logs #6571

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/late-kings-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

feat: Add deployment http targets to wrangler deploy logs, and add url to pages deploy logs
57 changes: 57 additions & 0 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,63 @@ describe("deploy", () => {
clearDialogs();
});

it("should output log file with deployment details", async () => {
vi.stubEnv("WRANGLER_OUTPUT_FILE_DIRECTORY", "output");
vi.stubEnv("WRANGLER_OUTPUT_FILE_PATH", "");
writeWorkerSource();
writeWranglerToml({
routes: ["example.com/some-route/*"],
workers_dev: true,
});
mockSubDomainRequest();
mockUploadWorkerRequest();
mockUpdateWorkerRequest({ enabled: false });
mockPublishRoutesRequest({ routes: ["example.com/some-route/*"] });

await runWrangler("deploy ./index.js");
expect(std.out).toMatchInlineSnapshot(`
"Total Upload: xx KiB / gzip: xx KiB
Worker Startup Time: 100 ms
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
https://test-name.test-sub-domain.workers.dev
example.com/some-route/*
Current Deployment ID: Galaxy-Class
Current Version ID: Galaxy-Class


Note: Deployment ID has been renamed to Version ID. Deployment ID is present to maintain compatibility with the previous behavior of this command. This output will change in a future version of Wrangler. To learn more visit: https://developers.cloudflare.com/workers/configuration/versions-and-deployments"
`);
expect(std.err).toMatchInlineSnapshot(`""`);

const outputFilePaths = fs.readdirSync("output");

expect(outputFilePaths.length).toEqual(1);
expect(outputFilePaths[0]).toMatch(/wrangler-output-.+\.json/);
const outputFile = fs.readFileSync(
path.join("output", outputFilePaths[0]),
"utf8"
);
const entries = outputFile
.split("\n")
.filter(Boolean)
.map((e) => JSON.parse(e));

expect(entries.find((e) => e.type === "deploy")).toMatchObject({
targets: [
"https://test-name.test-sub-domain.workers.dev",
"example.com/some-route/*",
],
// Omitting timestamp for matching
// timestamp: ...
type: "deploy",
version: 1,
version_id: "Galaxy-Class",
worker_name: "test-name",
worker_tag: "tag:test-name",
});
});

it("should resolve wrangler.toml relative to the entrypoint", async () => {
fs.mkdirSync("./some-path/worker", { recursive: true });
fs.writeFileSync(
Expand Down
4 changes: 4 additions & 0 deletions packages/wrangler/src/__tests__/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe("writeOutput()", () => {
worker_name: "Worker",
worker_tag: "ABCDE12345",
version_id: "1234",
targets: undefined,
});

const outputFile = readFileSync(WRANGLER_OUTPUT_FILE_PATH, "utf8");
Expand All @@ -102,6 +103,7 @@ describe("writeOutput()", () => {
worker_name: "Worker",
worker_tag: "ABCDE12345",
version_id: "1234",
targets: undefined,
},
]);
});
Expand Down Expand Up @@ -148,6 +150,7 @@ describe("writeOutput()", () => {
worker_name: "Worker",
worker_tag: "ABCDE12345",
version_id: "1234",
targets: undefined,
});

const outputFilePaths = readdirSync("output");
Expand All @@ -168,6 +171,7 @@ describe("writeOutput()", () => {
worker_name: "Worker",
worker_tag: "ABCDE12345",
version_id: "1234",
targets: undefined,
},
]);
});
Expand Down
10 changes: 8 additions & 2 deletions packages/wrangler/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ export default async function deploy(props: Props): Promise<{
sourceMapSize?: number;
deploymentId: string | null;
workerTag: string | null;
targets?: string[];
}> {
// TODO: warn if git/hg has uncommitted changes
const { config, accountId, name } = props;
Expand Down Expand Up @@ -866,14 +867,19 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
}

// deploy triggers
await triggersDeploy(props);
const targets = await triggersDeploy(props);

logger.log("Current Deployment ID:", deploymentId);
logger.log("Current Version ID:", deploymentId);

logVersionIdChange();

return { sourceMapSize, deploymentId, workerTag };
return {
sourceMapSize,
deploymentId,
workerTag,
targets: targets ?? [],
};
}

function deployWfpUserWorker(
Expand Down
3 changes: 2 additions & 1 deletion packages/wrangler/src/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export async function deployHandler(

const beforeUpload = Date.now();
const name = getScriptName(args, config);
const { sourceMapSize, deploymentId, workerTag } = await deploy({
const { sourceMapSize, deploymentId, workerTag, targets } = await deploy({
config,
accountId,
name,
Expand Down Expand Up @@ -370,6 +370,7 @@ export async function deployHandler(
worker_tag: workerTag,
// Note that the `deploymentId` returned from a simple deployment is actually the versionId of the uploaded version.
version_id: deploymentId,
targets,
});

await metrics.sendMetricsEvent(
Expand Down
14 changes: 14 additions & 0 deletions packages/wrangler/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ interface OutputEntryBase<T extends string> {
export type OutputEntry =
| OutputEntrySession
| OutputEntryDeployment
| OutputEntryPagesDeployment
| OutputEntryVersionUpload
| OutputEntryVersionDeployment;

Expand All @@ -92,6 +93,19 @@ export interface OutputEntryDeployment extends OutputEntryBase<"deploy"> {
worker_tag: string | null;
/** A GUID that identifies this deployed version of the Worker. This version is associated with an automatically created deployment, with this version set at 100%. */
version_id: string | null;
/** A list of URLs that represent the HTTP triggers associated with this deployment */
targets: string[] | undefined;
}

export interface OutputEntryPagesDeployment
extends OutputEntryBase<"pages-deploy"> {
version: 1;
/** The name of the Pages project. */
pages_project: string | null;
/** A GUID that identifies this Pages deployment. */
deployment_id: string | null;
/** The URL associated with this deployment */
url: string | undefined;
}

export interface OutputEntryVersionUpload
Expand Down
9 changes: 9 additions & 0 deletions packages/wrangler/src/pages/deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { prompt } from "../dialogs";
import { FatalError } from "../errors";
import { logger } from "../logger";
import * as metrics from "../metrics";
import { writeOutput } from "../output";
import { requireAuth } from "../user";
import {
MAX_DEPLOYMENT_STATUS_ATTEMPTS,
Expand Down Expand Up @@ -433,6 +434,14 @@ ${failureMessage}`,
);
}

writeOutput({
type: "pages-deploy",
version: 1,
pages_project: deploymentResponse.project_name,
deployment_id: deploymentResponse.id,
url: deploymentResponse.url,
});

await metrics.sendMetricsEvent("create pages deployment");
};

Expand Down
16 changes: 10 additions & 6 deletions packages/wrangler/src/triggers/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ type Props = {
experimentalVersions: boolean | undefined;
};

export default async function triggersDeploy(props: Props): Promise<void> {
export default async function triggersDeploy(
props: Props
): Promise<string[] | void> {
const { config, accountId, name: scriptName } = props;

const triggers = props.triggers || config.triggers?.crons;
Expand Down Expand Up @@ -253,13 +255,15 @@ export default async function triggersDeploy(props: Props): Promise<void> {
: `Published ${workerName}`;
logger.log(msg, formatTime(deployMs));

for (const target of targets.flat()) {
const flatTargets = targets.flat().map(
// Append protocol only on workers.dev domains
logger.log(
" ",
(target.endsWith("workers.dev") ? "https://" : "") + target
);
(target) => (target.endsWith("workers.dev") ? "https://" : "") + target
);

for (const target of flatTargets) {
logger.log(" ", target);
}
return flatTargets;
} else {
logger.log("No deploy targets for", workerName, formatTime(deployMs));
}
Expand Down
Loading