workers-sdk
workers-sdk copied to clipboard
Implement `versions deploy` command
What this PR solves / how to test:
This PR implements the versions deploy
command as a sibling command to the, already merged, versions upload
command. Both are still behind the --experimental-gradual-rollouts
flag.
Note: in the commands below, it is assumed you have followed the install instructions of the prerelease build (from the bot comment in this PR). You can, instead, replace "wrangler" with the prerelease URL from the bot comment.
The most common usage will be without args where the prompts will walk you through selecting Versions and percentages for each and adding a deployment message. A sane default is provided for each percentage, evenly distributing the remaining percentage across the remaining versions.
$ npx wrangler versions deploy --experimental-gradual-rollouts
You can also specify positional args in the form of <version-id>
or <version-id>@<percentage>
which will set the default selected Versions and the default associated percentage for each. The prompts are still presented but with prefilled defaults that the user can press ENTER to confirm.
# 1 version preselected by default
$ npx wrangler versions deploy 095f00a7-23a7-43b7-a227-e4c97cab5f22 --experimental-gradual-rollouts
# 2 versions preselected by default (the default percentage for each will be 50%)
$ npx wrangler versions deploy 095f00a7-23a7-43b7-a227-e4c97cab5f22 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2 -experimental-gradual-rollouts
# 2 versions preselected by default – one with explicit 10% traffic, the other with implicit 90%
$ npx wrangler versions deploy 095f00a7-23a7-43b7-a227-e4c97cab5f22@10% 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2 --experimental-gradual-rollouts
# ^ the 2nd version will have 90% by default (evenly distributed after the first version was assigned 10%)
# 2 versions preselected by default – both with explicit traffic 10% and 90%
$ npx wrangler versions deploy 095f00a7-23a7-43b7-a227-e4c97cab5f22@10% 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2@90% --experimental-gradual-rollouts
You can also specify named args --version-id
and --percentage
repeatedly. All --version-id
args are read in order into an array. All --percentage
args are read in order into an array. The indexes of each array are then used to correlate. By specifying less --percentage
args than --version-id
args, the percentages for the excess versions are deemed unspecified, like with positional args without @<percentage>
, and will have the remaining percentage distributed evenly as with positional/prompted percentages.
$ npx wrangler versions deploy --experimental-gradual-rollouts \
--version-id 095f00a7-23a7-43b7-a227-e4c97cab5f22 \
--percentage 10% \
--version-id 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2 \
--percentage 90%
# is equivalent to
$ npx wrangler versions deploy --experimental-gradual-rollouts \
--version-id 095f00a7-23a7-43b7-a227-e4c97cab5f22 \
--version-id 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2 \
--percentage 10% \
--percentage 90%
A mixture of positional and named args will work and should be relatively predictable, with positional args taking precedence.
By using the --yes
flag (TODO), the prompt defaults will be automatically accepted. This will allow the following:
# deploy 2 versions with 50% split
$ npx wrangler versions deploy 095f00a7-23a7-43b7-a227-e4c97cab5f22 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2 --yes --experimental-gradual-rollouts
# deploy 2 versions with 10% / 90% split
$ npx wrangler versions deploy 095f00a7-23a7-43b7-a227-e4c97cab5f22@10% 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2 --yes --experimental-gradual-rollouts
# deploy 2 versions with (explicit) 10% and (implicit) 90% split
$ npx wrangler versions deploy 095f00a7-23a7-43b7-a227-e4c97cab5f22@10% 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2 --yes --experimental-gradual-rollouts
# deploy 2 versions with (explicit) 10% and (explicit) 90% split
$ npx wrangler versions deploy 095f00a7-23a7-43b7-a227-e4c97cab5f22@10% 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2@90% --yes --experimental-gradual-rollouts
# deploy 2 versions with (explicit) 10% and (explicit) 90% split
$ npx wrangler versions deploy --yes --experimental-gradual-rollouts \
--version-id 095f00a7-23a7-43b7-a227-e4c97cab5f22 \
--percentage 10% \
--version-id 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2 \
--percentage 90%
# deploy 2 versions with (explicit) 10% and (implicit) 90% split
$ npx wrangler versions deploy --yes --experimental-gradual-rollouts \
--version-id 095f00a7-23a7-43b7-a227-e4c97cab5f22 \
--percentage 10% \
--version-id 1a88955c-2fbd-4a72-9d9b-3ba1e59842f2
Author has addressed the following:
- Tests
- [ ] Included
- [ ] Not necessary because:
- [x] TODO before merging
- Changeset (Changeset guidelines)
- [ ] Included
- [ ] Not necessary because:
- [x] TODO before merging
- Associated docs
- [ ] Issue(s)/PR(s):
- [x] Not necessary because: internal command for now, documentation coming before open beta.
Note for PR author:
We want to celebrate and highlight awesome PR review! If you think this PR received a particularly high-caliber review, please assign it the label highlight pr review
so future reviewers can take inspiration and learn from it.
🦋 Changeset detected
Latest commit: bab3451807ff08af662fddec121e2b7aacef2892
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 2 packages
Name | Type |
---|---|
wrangler | Minor |
@cloudflare/vitest-pool-workers | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
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/8256774955/npm-package-wrangler-5115
You can reference the automatically updated head of this PR with:
npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/5115/npm-package-wrangler-5115
Or you can use npx
with this latest build directly:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8256774955/npm-package-wrangler-5115 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8256774955/npm-package-create-cloudflare-5115 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8256774955/npm-package-cloudflare-kv-asset-handler-5115
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8256774955/npm-package-miniflare-5115
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8256774955/npm-package-cloudflare-pages-shared-5115
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8256774955/npm-package-cloudflare-vitest-pool-workers-5115
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.20240304.1 |
workerd |
1.20240304.0 | 1.20240304.0 |
workerd --version |
1.20240304.0 | 2024-03-04 |
Please ensure constraints are pinned, and miniflare
/workerd
minor versions match.
If I create a new Worker, publish a new version, and then run this, in interactive mode I'm shown:
➜ gradual-test git:(main) ✗ npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/8195782752/npm-package-wrangler-5115 versions deploy --experimental-gradual-rollouts
⛅️ wrangler 0.0.0-fb147c36
---------------------------
╭ Deploy Worker Versions by splitting traffic between multiple versions
│
├ Your current deployment has 1 version(s):
│
│ (100%) 19c005af-5788-4991-a2a0-00a080f2b650
│ Created: 3/7/2024, 4:20:39 PM
│ Tag: -
│ Message: -
│
╰ Which version(s) do you want to deploy? Use SPACE to select/unselect version(s) and ENTER to submit.
○ 7d80087b-422a-41f5-b4bc-c6bc38deeeb9
Created: 3/7/2024, 4:24:35 PM
Tag: -
Message: -
...and then no matter which version I select, I get the following error:
├ Which version(s) do you want to deploy?
├ 0 Worker Version(s) selected
│
✘ [ERROR] You must select at least 1 version to deploy.
(If I add specific version IDs as positional args then things work as expected, and this is looking really cool!)
cc @tanushreesharma-cf
@irvinebroque that's odd – have you had similar problems with C3's interactive prompts?
I don't have any issues inside VSCode's terminal or in iTerm2:
https://github.com/cloudflare/workers-sdk/assets/5822355/a2189b2f-edfe-4370-a06e-0c55239237be
Codecov Report
Attention: Patch coverage is 94.26230%
with 14 lines
in your changes are missing coverage. Please review.
Project coverage is 70.98%. Comparing base (
772d42e
) to head (bab3451
). Report is 1 commits behind head on main.
Additional details and impacted files
@@ Coverage Diff @@
## main #5115 +/- ##
==========================================
+ Coverage 70.47% 70.98% +0.50%
==========================================
Files 298 301 +3
Lines 15539 15828 +289
Branches 3999 4053 +54
==========================================
+ Hits 10951 11235 +284
- Misses 4588 4593 +5
Files | Coverage Δ | |
---|---|---|
packages/wrangler/e2e/helpers/normalize.ts | 93.75% <100.00%> (ø) |
|
...ler/src/__tests__/helpers/msw/handlers/versions.ts | 100.00% <100.00%> (ø) |
|
...ckages/wrangler/src/__tests__/helpers/msw/index.ts | 100.00% <100.00%> (ø) |
|
packages/wrangler/src/index.ts | 90.44% <100.00%> (+0.66%) |
:arrow_up: |
packages/wrangler/src/metrics/send-event.ts | 100.00% <ø> (ø) |
|
packages/wrangler/src/versions/deploy.ts | 93.60% <93.60%> (ø) |
Had to rebase because of conflict in main