Skip to content

Commit c4c86f8

Browse files
authored
[wrangler] Add --tag and --message to deploy command (#12445) (#12560)
1 parent 5a868a0 commit c4c86f8

File tree

5 files changed

+134
-2
lines changed

5 files changed

+134
-2
lines changed

.changeset/salty-mirrors-turn.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Support `--tag` and `--message` flags on `wrangler deploy`
6+
7+
They have the same behavior that they do as during `wrangler versions upload`, as both
8+
are set on the version.
9+
10+
The message is also reused for the deployment as well, with the same behavior as used
11+
during `wrangler versions deploy`.

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16696,6 +16696,89 @@ export default{
1669616696
expect(std.warn).toMatchInlineSnapshot(`""`);
1669716697
});
1669816698
});
16699+
16700+
describe("--tag and --message", () => {
16701+
it("should send tag and message annotations via the new versions API", async () => {
16702+
writeWranglerConfig();
16703+
writeWorkerSource();
16704+
mockSubDomainRequest();
16705+
mockUploadWorkerRequest({
16706+
expectedAnnotations: {
16707+
"workers/message": "my deploy message",
16708+
"workers/tag": "v1.0.0",
16709+
},
16710+
expectedDeploymentMessage: "my deploy message",
16711+
});
16712+
16713+
await runWrangler(
16714+
'deploy ./index --tag v1.0.0 --message "my deploy message"'
16715+
);
16716+
expect(std.out).toContain("Uploaded test-name");
16717+
expect(std.out).toContain("Current Version ID: Galaxy-Class");
16718+
});
16719+
16720+
it("should send tag and message annotations via the legacy PUT API", async () => {
16721+
writeWranglerConfig();
16722+
writeWorkerSource();
16723+
mockSubDomainRequest();
16724+
mockUploadWorkerRequest({
16725+
expectedAnnotations: {
16726+
"workers/message": "legacy deploy msg",
16727+
"workers/tag": "v2.0.0",
16728+
},
16729+
expectedDispatchNamespace: "test-dispatch-namespace",
16730+
});
16731+
16732+
await runWrangler(
16733+
'deploy ./index --dispatch-namespace test-dispatch-namespace --tag v2.0.0 --message "legacy deploy msg"'
16734+
);
16735+
expect(std.out).toContain("Uploaded test-name");
16736+
});
16737+
16738+
it("should send only --tag without --message", async () => {
16739+
writeWranglerConfig();
16740+
writeWorkerSource();
16741+
mockSubDomainRequest();
16742+
mockUploadWorkerRequest({
16743+
expectedAnnotations: {
16744+
"workers/message": undefined,
16745+
"workers/tag": "v1.0.0",
16746+
},
16747+
expectedDeploymentMessage: undefined,
16748+
});
16749+
16750+
await runWrangler("deploy ./index --tag v1.0.0");
16751+
expect(std.out).toContain("Uploaded test-name");
16752+
});
16753+
16754+
it("should send only --message without --tag", async () => {
16755+
writeWranglerConfig();
16756+
writeWorkerSource();
16757+
mockSubDomainRequest();
16758+
mockUploadWorkerRequest({
16759+
expectedAnnotations: {
16760+
"workers/message": "just a message",
16761+
"workers/tag": undefined,
16762+
},
16763+
expectedDeploymentMessage: "just a message",
16764+
});
16765+
16766+
await runWrangler('deploy ./index --message "just a message"');
16767+
expect(std.out).toContain("Uploaded test-name");
16768+
});
16769+
16770+
it("should not set annotations when neither --tag nor --message is provided", async () => {
16771+
writeWranglerConfig();
16772+
writeWorkerSource();
16773+
mockSubDomainRequest();
16774+
mockUploadWorkerRequest({
16775+
expectedAnnotations: undefined,
16776+
});
16777+
16778+
await runWrangler("deploy ./index");
16779+
expect(std.out).toContain("Uploaded test-name");
16780+
});
16781+
});
1669916782
});
1670016783

1670116784
/** Write mock assets to the file system so they can be uploaded. */

packages/wrangler/src/__tests__/helpers/mock-upload-worker.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export function mockUploadWorkerRequest(
5555
expectedObservability?: CfWorkerInit["observability"];
5656
expectedSettingsPatch?: Partial<NonVersionedScriptSettings>;
5757
expectedContainers?: { class_name: string }[];
58+
expectedAnnotations?: Record<string, string | undefined>;
59+
expectedDeploymentMessage?: string;
5860
} = {}
5961
) {
6062
const handleUpload: HttpResponseResolver = async ({ params, request }) => {
@@ -142,6 +144,9 @@ export function mockUploadWorkerRequest(
142144
if ("expectedContainers" in options) {
143145
expect(metadata.containers).toEqual(expectedContainers);
144146
}
147+
if ("expectedAnnotations" in options) {
148+
expect(metadata.annotations).toEqual(expectedAnnotations);
149+
}
145150

146151
if (expectedUnsafeMetaData !== undefined) {
147152
Object.keys(expectedUnsafeMetaData).forEach((key) => {
@@ -203,12 +208,14 @@ export function mockUploadWorkerRequest(
203208
expectedCapnpSchema,
204209
expectedLimits,
205210
expectedContainers,
211+
expectedAnnotations,
206212
keepVars,
207213
keepSecrets,
208214
expectedDispatchNamespace,
209215
useOldUploadApi,
210216
expectedObservability,
211217
expectedSettingsPatch,
218+
expectedDeploymentMessage,
212219
} = options;
213220

214221
const expectedScriptName =
@@ -244,7 +251,17 @@ export function mockUploadWorkerRequest(
244251
),
245252
http.post(
246253
"*/accounts/:accountId/workers/scripts/:scriptName/deployments",
247-
() => HttpResponse.json(createFetchResult({ id: "Deployment-ID" }))
254+
async ({ request }) => {
255+
if ("expectedDeploymentMessage" in options) {
256+
const body = (await request.json()) as {
257+
annotations?: { "workers/message"?: string };
258+
};
259+
expect(body.annotations?.["workers/message"]).toEqual(
260+
expectedDeploymentMessage
261+
);
262+
}
263+
return HttpResponse.json(createFetchResult({ id: "Deployment-ID" }));
264+
}
248265
),
249266
http.patch(
250267
"*/accounts/:accountId/workers/scripts/:scriptName/script-settings",

packages/wrangler/src/deploy/deploy.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ type Props = {
134134
metafile: string | boolean | undefined;
135135
containersRollout: "immediate" | "gradual" | undefined;
136136
strict: boolean | undefined;
137+
tag: string | undefined;
138+
message: string | undefined;
137139
};
138140

139141
export type RouteObject = ZoneIdRoute | ZoneNameRoute | CustomDomainRoute;
@@ -858,6 +860,13 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
858860
tail_consumers: config.tail_consumers,
859861
streaming_tail_consumers: config.streaming_tail_consumers,
860862
limits: config.limits,
863+
annotations:
864+
props.tag || props.message
865+
? {
866+
"workers/message": props.message,
867+
"workers/tag": props.tag,
868+
}
869+
: undefined,
861870
assets:
862871
props.assetsOptions && assetsJwt
863872
? {
@@ -1014,7 +1023,7 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
10141023
accountId,
10151024
scriptName,
10161025
versionMap,
1017-
undefined
1026+
props.message
10181027
);
10191028

10201029
// Update service and environment tags when using environments

packages/wrangler/src/deploy/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ export const deployCommand = createCommand({
235235
"Rollout strategy for Containers changes. If set to immediate, it will override `rollout_percentage_steps` if configured and roll out to 100% of instances in one step. ",
236236
choices: ["immediate", "gradual"] as const,
237237
},
238+
tag: {
239+
describe: "A tag for this Worker Version",
240+
type: "string",
241+
requiresArg: true,
242+
},
243+
message: {
244+
describe: "A descriptive message for this Worker Version and Deployment",
245+
type: "string",
246+
requiresArg: true,
247+
},
238248
strict: {
239249
describe:
240250
"Enables strict mode for the deploy command, this prevents deployments to occur when there are even small potential risks.",
@@ -492,6 +502,8 @@ export const deployCommand = createCommand({
492502
experimentalAutoCreate: args.experimentalAutoCreate,
493503
containersRollout: args.containersRollout,
494504
strict: args.strict,
505+
tag: args.tag,
506+
message: args.message,
495507
});
496508

497509
writeOutput({

0 commit comments

Comments
 (0)