-
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
feat: wrangler deploy prompts warning with deployment #5992
Conversation
|
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9502295694/npm-package-wrangler-5992 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5992/npm-package-wrangler-5992 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9502295694/npm-package-wrangler-5992 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9502295694/npm-package-create-cloudflare-5992 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9502295694/npm-package-cloudflare-kv-asset-handler-5992 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9502295694/npm-package-miniflare-5992 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9502295694/npm-package-cloudflare-pages-shared-5992 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/9502295694/npm-package-cloudflare-vitest-pool-workers-5992 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
const latest = await fetchLatestDeployment(accountId, scriptName); | ||
if (latest && latest.versions.length >= 2) { | ||
logger.warn( | ||
`Your latest deployment has multiple versions.\n"wrangler deploy" will upload a new version and deploy it globally immediately.` |
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.
Should this also include a mention of "wrangler versions deploy" as the alternative?
d0cae7e
to
ca2cf3f
Compare
We should return the current status of the deployment + allow users to override and wrangler deploy. Copy (having a hard time with formatting in comments):
|
ca2cf3f
to
aa18a35
Compare
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 comment
The 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
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 comment
The 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
@@ -423,6 +428,34 @@ describe("deploy", () => { | |||
`); | |||
}); | |||
|
|||
it("should warn user when worker has deployment with multiple versions", async () => { |
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?
cc0fd7c
to
a1d66af
Compare
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.
Regarding #5992 (comment)
I see now that all the tests are non-interactive.
Why are there not tests of the user interactively agreeing or disagreeing with the deployment?
packages/cli/index.ts
Outdated
} = {} | ||
) => { | ||
logRaw( | ||
format(msg, { | ||
firstLinePrefix: gray(shape) + space() + status.warning, | ||
linePrefix: gray(shapes.bar), | ||
newlineBefore: true, | ||
newlineBefore: newlineBefore, |
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.
NIT:
newlineBefore: newlineBefore, | |
newlineBefore, |
const versionCache: VersionCache = new Map(); | ||
const versionIds = latest.versions.map((v) => v.version_id); | ||
await fetchVersions(accountId, scriptName, versionCache, ...versionIds); | ||
|
||
const versions = latest.versions.map((v) => { | ||
const version = versionCache.get(v.version_id); | ||
assert(version); | ||
return version; | ||
}); | ||
|
||
const traffic = new Map( | ||
latest.versions.map((v) => [v.version_id, v.percentage]) | ||
); |
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.
Besides styling, reusing printLatestDeployments would have also avoided the need to duplicate this logic.
The only difference I see is the preamble "current" vs "last":
- `${leftT} Your current deployment has ${versions.length} version(s):`
+ `${leftT} Your last deployment has ${versions.length} version(s):`
nit: you can adapt printLatestDeployment to accept an additional param: adjective: "current" | "last"
and therefore trim this function down and avoid the duplication
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.
What I didn't like about printLatestDeployment
is that it would fetch the deployment again when I already had it. Ended up refactoring to a function named printDeployment
that lets you pass and print any deployment as a parameter.
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.
I had an idea to pass a callback param like skipIf(deployment: ApiDeployment) => boolean
which would enable flow control using the one api request
but this is fine for now, and I can refactor in a follow up if we decide it's worth it
Styling of the warning about multiple deployments during `wrangler deploy` should be consistent with `wrangler versions` styling.
a1d66af
to
841bc7d
Compare
Co-authored-by: Rahul Sethi <[email protected]>
Co-authored-by: Rahul Sethi <[email protected]>
Congratulations @danielrs, you just earned a holobyte! Here it is: https://holopin.io/holobyte/clxdf4dwm87490dl3krezvud5 This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. |
What this PR solves / how to test
Shows a warning to avoid accidental overwrite of a percentage-based deployment.
Author has addressed the following