Skip to content
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

Conversation

danielrs
Copy link
Contributor

@danielrs danielrs commented Jun 6, 2024

What this PR solves / how to test

Shows a warning to avoid accidental overwrite of a percentage-based deployment.

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Included
    • Not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required / Maybe required
    • Not required because:
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Included
    • Not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Not necessary because:

@danielrs danielrs requested a review from a team as a code owner June 6, 2024 23:57
Copy link

changeset-bot bot commented Jun 6, 2024

⚠️ No Changeset found

Latest commit: 89dca41

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

github-actions bot commented Jun 6, 2024

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 with this latest build directly:

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.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240605.0
workerd 1.20240610.1 1.20240610.1
workerd --version 1.20240610.1 2024-06-10

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

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.`
Copy link
Contributor

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?

@danielrs danielrs force-pushed the drivas/wrangler-deploy-warning-on-overwrite branch from d0cae7e to ca2cf3f Compare June 7, 2024 13:52
@tanushree-sharma
Copy link

tanushree-sharma commented Jun 9, 2024

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):

> wrangler deploy

▲ [WARNING] Your last deployment has multiple versions. To progress this deployment use "wrangler versions deploy" instead. 

Currently deployed versions:

Version(s):  (50%) d58c1fb8-6015-410f-8fb7-e2818788b337
                    Created:  2024-06-07T13:21:14.974Z
             
                   (50%) 2ea0b4e6-f593-41cf-8a70-f0ef64bb0b02
                   Created:  2024-06-05T22:17:53.355Z
 
"wrangler deploy" will upload a new version and deploy it globally immediately. Are you sure you want to continue? (y/n). 

@danielrs danielrs force-pushed the drivas/wrangler-deploy-warning-on-overwrite branch from ca2cf3f to aa18a35 Compare June 10, 2024 20:01
@danielrs danielrs requested a review from RamIdeas June 10, 2024 20:23
Comment on lines 225 to 252
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.
Copy link
Contributor

@RamIdeas RamIdeas Jun 12, 2024

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

Comment on lines 261 to 263
return await confirm(
`"wrangler deploy" will upload a new version and deploy it globally immediately.\nAre you sure you want to continue?`
);
Copy link
Contributor

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 () => {
Copy link
Contributor

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?

@danielrs danielrs force-pushed the drivas/wrangler-deploy-warning-on-overwrite branch 2 times, most recently from cc0fd7c to a1d66af Compare June 12, 2024 21:12
Copy link
Contributor

@petebacondarwin petebacondarwin left a 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?

} = {}
) => {
logRaw(
format(msg, {
firstLinePrefix: gray(shape) + space() + status.warning,
linePrefix: gray(shapes.bar),
newlineBefore: true,
newlineBefore: newlineBefore,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:

Suggested change
newlineBefore: newlineBefore,
newlineBefore,

Comment on lines 224 to 236
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])
);
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.
@danielrs danielrs force-pushed the drivas/wrangler-deploy-warning-on-overwrite branch from a1d66af to 841bc7d Compare June 13, 2024 15:01
@danielrs danielrs requested a review from RamIdeas June 13, 2024 15:06
@petebacondarwin petebacondarwin merged commit c13fb91 into cloudflare:main Jun 13, 2024
19 checks passed
@workers-devprod workers-devprod added the contribution [Holopin] Recognizes an open-source contribution, big or small label Jun 13, 2024
Copy link

holopin-bot bot commented Jun 13, 2024

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.
Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

petebacondarwin added a commit that referenced this pull request Jun 13, 2024
@danielrs danielrs deleted the drivas/wrangler-deploy-warning-on-overwrite branch June 13, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution [Holopin] Recognizes an open-source contribution, big or small
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants