Skip to content

Commit

Permalink
fix: tweak the properties of the new Wrangler output file entries for…
Browse files Browse the repository at this point in the history
… better consistency (#6440)
  • Loading branch information
petebacondarwin authored Aug 8, 2024
1 parent 19b1e69 commit 09b5092
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-lobsters-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: tweak the properties of the new Wrangler output file entries for better consistency
16 changes: 8 additions & 8 deletions packages/wrangler/src/__tests__/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ describe("writeOutput()", () => {
log_file_path: "some/log/path.log",
});
writeOutput({
type: "deployment",
type: "deploy",
version: 1,
worker_name: "Worker",
worker_tag: "ABCDE12345",
deployment_id: "1234",
version_id: "1234",
});

const outputFile = readFileSync(WRANGLER_OUTPUT_FILE_PATH, "utf8");
Expand All @@ -117,11 +117,11 @@ describe("writeOutput()", () => {
log_file_path: "some/log/path.log",
},
{
type: "deployment",
type: "deploy",
version: 1,
worker_name: "Worker",
worker_tag: "ABCDE12345",
deployment_id: "1234",
version_id: "1234",
},
]);
} finally {
Expand Down Expand Up @@ -178,11 +178,11 @@ describe("writeOutput()", () => {
log_file_path: "some/log/path.log",
});
writeOutput({
type: "deployment",
type: "deploy",
version: 1,
worker_name: "Worker",
worker_tag: "ABCDE12345",
deployment_id: "1234",
version_id: "1234",
});

const outputFilePaths = readdirSync("output");
Expand All @@ -201,11 +201,11 @@ describe("writeOutput()", () => {
log_file_path: "some/log/path.log",
},
{
type: "deployment",
type: "deploy",
version: 1,
worker_name: "Worker",
worker_tag: "ABCDE12345",
deployment_id: "1234",
version_id: "1234",
},
]);
} finally {
Expand Down
5 changes: 3 additions & 2 deletions packages/wrangler/src/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,12 @@ export async function deployHandler(
});

writeOutput({
type: "deployment",
type: "deploy",
version: 1,
worker_name: name ?? null,
worker_tag: workerTag,
deployment_id: deploymentId,
// Note that the `deploymentId` returned from a simple deployment is actually the versionId of the uploaded version.
version_id: deploymentId,
});

await metrics.sendMetricsEvent(
Expand Down
18 changes: 16 additions & 2 deletions packages/wrangler/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,30 +76,44 @@ export type StampedOutputEntry = { timestamp: string } & OutputEntry;
export interface OutputEntrySession
extends OutputEntryBase<"wrangler-session"> {
version: 1;
/** The semver version string taken from Wrangler's package.json. */
wrangler_version: string;
/** The arguments passed to Wrangler. */
command_line_args: string[];
/** The absolute path to a file that contains debug logs for this Wrangler instance. */
log_file_path: string;
}

export interface OutputEntryDeployment extends OutputEntryBase<"deployment"> {
export interface OutputEntryDeployment extends OutputEntryBase<"deploy"> {
version: 1;
/** The name of the Worker. */
worker_name: string | null;
/** The GUID that identifies the Worker. This never changes even if the name is changed. */
worker_tag: string | null;
deployment_id: 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;
}

export interface OutputEntryVersionUpload
extends OutputEntryBase<"version-upload"> {
version: 1;
/** The name of the Worker. */
worker_name: string | null;
/** The GUID that identifies the Worker. This never changes even if the name is changed. */
worker_tag: string | null;
/** A GUID that identifies this uploaded, but not yet deployed, version of the Worker. This version will need to be "deployed" to receive traffic. */
version_id: string | null;
}

export interface OutputEntryVersionDeployment
extends OutputEntryBase<"version-deploy"> {
version: 1;
/** The name of the Worker. */
worker_name: string | null;
/** The GUID that identifies the Worker. This never changes even if the name is changed. */
worker_tag: string | null;
/** The ID of the gradual rollout deployment. */
deployment_id: string;
/** The percentage of traffic that goes to each version. */
version_traffic: Map<string, number>;
}
2 changes: 1 addition & 1 deletion packages/wrangler/src/versions/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export async function createDeployment(
message: string | undefined,
force?: boolean
) {
return await fetchResult(
return await fetchResult<{ id: string }>(
`/accounts/${accountId}/workers/scripts/${workerName}/deployments${force ? "?force=true" : ""}`,
{
method: "POST",
Expand Down
8 changes: 5 additions & 3 deletions packages/wrangler/src/versions/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ export async function versionsDeployHandler(args: VersionsDeployArgs) {

const start = Date.now();

await spinnerWhile({
const { id: deploymentId } = await spinnerWhile({
startMessage: `Deploying ${confirmedVersionsToDeploy.length} version(s)`,
async promise() {
await createDeployment(
promise() {
return createDeployment(
accountId,
workerName,
confirmedVersionTraffic,
Expand Down Expand Up @@ -220,6 +220,8 @@ export async function versionsDeployHandler(args: VersionsDeployArgs) {
version: 1,
worker_name: workerName,
worker_tag: workerTag,
// NOTE this deploymentId is related to the gradual rollout of the versions given in the version_traffic.
deployment_id: deploymentId,
version_traffic: confirmedVersionTraffic,
});
}
Expand Down

0 comments on commit 09b5092

Please sign in to comment.