-
Notifications
You must be signed in to change notification settings - Fork 667
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
feat: wrangler deploy prompts warning with deployment #5992
Changes from 1 commit
aa18a35
841bc7d
8439ca3
89dca41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,102 @@ | ||
import { http, HttpResponse } from "msw"; | ||
import { createFetchResult } from "../index"; | ||
import type { ApiDeployment, ApiVersion } from "../../../../versions/types"; | ||
|
||
export const mswListNewDeploymentsLatestFull = [ | ||
http.get( | ||
"*/accounts/:accountId/workers/scripts/:scriptName/deployments", | ||
({ params }) => { | ||
return HttpResponse.json( | ||
createFetchResult({ | ||
deployments: [ | ||
{ | ||
id: `deployment:${params["scriptName"]}`, | ||
source: "api", | ||
strategy: "percentage", | ||
author_email: "[email protected]", | ||
created_on: "2021-01-01T00:00:00.000000Z", | ||
versions: [ | ||
{ | ||
version_id: `${params["scriptName"]}:version:0`, | ||
percentage: 100.0, | ||
}, | ||
], | ||
}, | ||
] as Array<ApiDeployment>, | ||
}) | ||
); | ||
}, | ||
{ once: true } | ||
), | ||
http.get( | ||
"*/accounts/:accountId/workers/scripts/:scriptName/versions/:version", | ||
({ params }) => { | ||
return HttpResponse.json( | ||
createFetchResult({ | ||
id: params["version"], | ||
number: 1, | ||
metadata: { | ||
created_on: "2021-01-01T00:00:00.000000Z", | ||
modified_on: "2021-01-01T00:00:00.000000Z", | ||
source: "api", | ||
author_email: "[email protected]", | ||
}, | ||
} as ApiVersion) | ||
); | ||
}, | ||
{ once: false } | ||
), | ||
]; | ||
|
||
export const mswListNewDeploymentsLatestFiftyFifty = [ | ||
http.get( | ||
"*/accounts/:accountId/workers/scripts/:scriptName/deployments", | ||
({ params }) => { | ||
return HttpResponse.json( | ||
createFetchResult({ | ||
deployments: [ | ||
{ | ||
id: `deployment:${params["scriptName"]}`, | ||
source: "api", | ||
strategy: "percentage", | ||
author_email: "[email protected]", | ||
created_on: "2021-01-01T00:00:00.000000Z", | ||
versions: [ | ||
{ | ||
version_id: `${params["scriptName"]}:version:0`, | ||
percentage: 50.0, | ||
}, | ||
{ | ||
version_id: `${params["scriptName"]}:version:1`, | ||
percentage: 50.0, | ||
}, | ||
], | ||
}, | ||
] as Array<ApiDeployment>, | ||
}) | ||
); | ||
}, | ||
{ once: true } | ||
), | ||
http.get( | ||
"*/accounts/:accountId/workers/scripts/:scriptName/versions/:version", | ||
({ params }) => { | ||
return HttpResponse.json( | ||
createFetchResult({ | ||
id: params["version"], | ||
number: 1, | ||
metadata: { | ||
created_on: "2021-01-01T00:00:00.000000Z", | ||
modified_on: "2021-01-01T00:00:00.000000Z", | ||
source: "api", | ||
author_email: "[email protected]", | ||
}, | ||
} as ApiVersion) | ||
); | ||
}, | ||
{ once: false } | ||
), | ||
]; | ||
|
||
export const mswListNewDeployments = http.get( | ||
"*/accounts/:accountId/workers/scripts/:workerName/deployments", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,18 @@ import { | |
spinnerWhile, | ||
} from "@cloudflare/cli/interactive"; | ||
import { findWranglerToml, readConfig } from "../config"; | ||
import { confirm } from "../dialogs"; | ||
import { UserError } from "../errors"; | ||
import { logger } from "../logger"; | ||
import * as metrics from "../metrics"; | ||
import { APIError } from "../parse"; | ||
import { printWranglerBanner } from "../update-check"; | ||
import { requireAuth } from "../user"; | ||
import formatLabelledValues from "../utils/render-labelled-values"; | ||
import { | ||
createDeployment, | ||
fetchDeployableVersions, | ||
fetchLatestDeployment, | ||
fetchLatestDeploymentVersions, | ||
fetchVersions, | ||
patchNonVersionedScriptSettings, | ||
|
@@ -205,6 +209,68 @@ function getConfig( | |
return config; | ||
} | ||
|
||
/** | ||
* Prompts the user for confirmation when overwriting the latest deployment, given that it's split. | ||
*/ | ||
export async function confirmLatestDeploymentOverwrite( | ||
accountId: string, | ||
scriptName: string | ||
) { | ||
try { | ||
const latest = await fetchLatestDeployment(accountId, scriptName); | ||
if (latest && latest.versions.length >= 2) { | ||
// Fetch the version details. | ||
|
||
const versionCache: VersionCache = new Map(); | ||
const versionIds = latest.versions.map((v) => v.version_id); | ||
await fetchVersions(accountId, scriptName, versionCache, ...versionIds); | ||
|
||
// Format each version. | ||
|
||
const formattedVersions = latest.versions.map((traffic) => { | ||
const version = versionCache.get(traffic.version_id); | ||
assert(version); | ||
const percentage = brandColor(`(${traffic.percentage}%)`); | ||
const details = formatLabelledValues( | ||
{ Created: new Date(version.metadata["created_on"]).toISOString() }, | ||
{ | ||
indentationCount: 4, | ||
labelJustification: "right", | ||
formatLabel: (label) => gray(label + ":"), | ||
formatValue: (value) => gray(value), | ||
} | ||
); | ||
return `${percentage} ${version.id}\n${details}`; | ||
}); | ||
|
||
// Format deployment. | ||
|
||
const formattedDeployment = formatLabelledValues({ | ||
"Version(s)": formattedVersions.join("\n\n"), | ||
}); | ||
|
||
// Print message and confirmation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this all be replaced with a call to printLatestDeployment (the function right below this one)? And then the styling will remain consistent |
||
|
||
logger.warn( | ||
`Your last deployment has multiple versions. To progress this deployment use "wrangler versions deploy" instead. | ||
Currently deployed versions: | ||
|
||
${formattedDeployment}` | ||
); | ||
|
||
return await confirm( | ||
`"wrangler deploy" will upload a new version and deploy it globally immediately.\nAre you sure you want to continue?` | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use inputPrompt instead of confirm please? There are other usages in this file you can use for reference |
||
} | ||
} catch (e) { | ||
const isNotFound = e instanceof APIError && e.code == 10007; | ||
if (!isNotFound) { | ||
throw e; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
export async function printLatestDeployment( | ||
accountId: string, | ||
workerName: string, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a test that checks what happens if the user says yes?
Also what happens if the console is non-interactive? Can that be tested too?