Skip to content
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
7 changes: 7 additions & 0 deletions .changeset/slow-masks-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

Skip confirmation prompts in `wrangler versions deploy` when versions are provided as CLI arguments

Passing version IDs or version specs to `wrangler versions deploy` now applies those values directly instead of opening interactive prompts to confirm the same versions and percentages. This makes the command easier to automate without requiring `--yes`.
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,22 @@ describe("versions deploy", () => {
`);
});

test("1 version @ (implicit) 100% without --yes", async ({ expect }) => {
const result = runWrangler(
"versions deploy 10000000-0000-0000-0000-000000000000"
);

await expect(result).resolves.toBeUndefined();

const output = normalizeOutput(cliStd.out);
expect(output).toContain(
"SUCCESS Deployed test-name version 00000000-0000-0000-0000-000000000000 at 100%"
);
expect(output).not.toContain(
"Use SPACE to select/unselect version(s) and ENTER to submit."
);
});

test("1 version @ (explicit) 100%", async ({ expect }) => {
const result = runWrangler(
"versions deploy 10000000-0000-0000-0000-000000000000@100% --yes"
Expand Down Expand Up @@ -537,6 +553,40 @@ describe("versions deploy", () => {
`);
});

test("2 versions @ (explicit) 40% + (explicit) 60% without --yes", async ({
expect,
}) => {
const result = runWrangler(
"versions deploy 10000000-0000-0000-0000-000000000000@40% 20000000-0000-0000-0000-000000000000@60%"
);

await expect(result).resolves.toBeUndefined();

const output = normalizeOutput(cliStd.out);
expect(output).toContain(
"SUCCESS Deployed test-name version 00000000-0000-0000-0000-000000000000 at 40% and version 00000000-0000-0000-0000-000000000000 at 60%"
);
expect(output).not.toContain(
"Use SPACE to select/unselect version(s) and ENTER to submit."
);
});

test("--version-id and --percentage without --yes", async ({ expect }) => {
const result = runWrangler(
"versions deploy --version-id 10000000-0000-0000-0000-000000000000 --percentage 100"
);

await expect(result).resolves.toBeUndefined();

const output = normalizeOutput(cliStd.out);
expect(output).toContain(
"SUCCESS Deployed test-name version 00000000-0000-0000-0000-000000000000 at 100%"
);
expect(output).not.toContain(
"Use SPACE to select/unselect version(s) and ENTER to submit."
);
});

describe("max versions restrictions (temp)", () => {
test("2+ versions fails", async ({ expect }) => {
msw.use(mswGetVersion30000000);
Expand Down
31 changes: 16 additions & 15 deletions packages/wrangler/src/versions/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const versionsDeployCommand = createCommand({
},
"version-specs": {
describe:
"Shorthand notation to deploy Worker Version(s) [<version-id>@<percentage>..]",
"Shorthand notation to deploy Worker Version(s) [<version-id>@<percentage>..]. Omitted percentages share the remaining traffic.",
type: "string",
array: true,
},
Expand Down Expand Up @@ -117,6 +117,7 @@ export const versionsDeployCommand = createCommand({

const versionCache: VersionCache = new Map();
const optionalVersionTraffic = parseVersionSpecs(args);
const acceptPromptDefaults = args.yes || optionalVersionTraffic.size > 0;

cli.startSection(
"Deploy Worker Versions",
Expand All @@ -133,7 +134,7 @@ export const versionsDeployCommand = createCommand({
workerName,
[...optionalVersionTraffic.keys()],
versionCache,
args.yes
acceptPromptDefaults
);

// validate we have at least 1 version
Expand All @@ -155,15 +156,15 @@ export const versionsDeployCommand = createCommand({
const confirmedVersionTraffic = await promptPercentages(
confirmedVersionsToDeploy,
optionalVersionTraffic,
args.yes
acceptPromptDefaults
);

// prompt for deployment message
const message = await inputPrompt<string | undefined>({
type: "text",
label: "Deployment message",
defaultValue: args.message,
acceptDefault: args.yes,
acceptDefault: acceptPromptDefaults,
question: "Add a deployment message",
helpText: "(optional)",
});
Expand Down Expand Up @@ -351,7 +352,7 @@ function formatVersions(
* @param accountId
* @param workerName
* @param defaultSelectedVersionIds
* @param yesFlag
* @param acceptDefault
* @returns
*/
async function promptVersionsToDeploy(
Expand All @@ -360,13 +361,13 @@ async function promptVersionsToDeploy(
workerName: string,
defaultSelectedVersionIds: VersionId[],
versionCache: VersionCache,
yesFlag: boolean
acceptDefault: boolean
): Promise<VersionId[]> {
// If the user has already specified all versions they want to deploy and
// has passed --yes (so there's no interactive prompt), skip fetching the
// the defaults will be accepted (so there's no interactive prompt), skip fetching the
// full deployable-versions list and only fetch the specific versions needed.
const skipDeployableVersionsFetch =
yesFlag && defaultSelectedVersionIds.length > 0;
acceptDefault && defaultSelectedVersionIds.length > 0;

await spinnerWhile({
startMessage: "Fetching versions",
Expand Down Expand Up @@ -414,7 +415,7 @@ ${ZERO_WIDTH_SPACE} Message: ${
label: "",
helpText: "Use SPACE to select/unselect version(s) and ENTER to submit.",
defaultValue: defaultSelectedVersionIds,
acceptDefault: yesFlag,
acceptDefault,
validate(versionIds) {
if (versionIds === undefined) {
return `You must select at least 1 version to deploy.`;
Expand Down Expand Up @@ -464,14 +465,14 @@ ${grayBar} ${gray(
*
* @param versionIds The Version IDs the user has selected to deploy
* @param optionalVersionTraffic The percentages the user has specified as args (if any)
* @param yesFlag Whether the user specified the --yes flag
* @param acceptDefault Whether prompt defaults should be accepted automatically
* @param confirmedVersionTraffic The percentages the user has already entered. Used for recursive calls.
* @returns A Map of Version IDs to their respective percentages confirmed by the user, totaling 100%
*/
async function promptPercentages(
versionIds: VersionId[],
optionalVersionTraffic: Map<VersionId, OptionalPercentage>,
yesFlag: boolean,
acceptDefault: boolean,
confirmedVersionTraffic = new Map<VersionId, Percentage>()
): Promise<Map<VersionId, Percentage>> {
let n = 0;
Expand All @@ -497,7 +498,7 @@ async function promptPercentages(
label: `Traffic`,
defaultValue,
initialValue: confirmedVersionTraffic.get(versionId)?.toString(), // if the user already entered a value, override the default
acceptDefault: yesFlag,
acceptDefault,
format: (val) => `${val}%`,
validate: (val) => {
const input = val !== "" ? val : defaultValue;
Expand Down Expand Up @@ -538,9 +539,9 @@ async function promptPercentages(
validateTrafficSubtotal(subtotal);
} catch (err) {
if (err instanceof UserError) {
// if the user has indicated they'll accept all defaults (yesFlag)
// if the user has indicated they'll accept all defaults
// then rethrow to avoid an infinite loop of reprompting
if (yesFlag) {
if (acceptDefault) {
throw err;
}

Expand All @@ -549,7 +550,7 @@ async function promptPercentages(
return promptPercentages(
versionIds,
optionalVersionTraffic,
yesFlag,
acceptDefault,
confirmedVersionTraffic
);
}
Expand Down
Loading