cloudflare / cloudflare/workers-sdk
wrangler versions upload --preview-alias rejects raw WORKERS_CI_BRANCH values containing slashes in Workers Builds
- Dominant language
- TypeScript
- Stars
- 4.5k
- Forks
- 1.5k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 186
Description
### What versions & operating system are you using?
System:
OS: Windows 11 10.0.26200
CPU: (16) x64 AMD Ryzen 7 7700 8-Core Processor
Memory: 16.09 GB / 31.11 GB
Binaries:
Node: 22.22.3 - C:\nvm4w\nodejs\node.EXE
npm: 11.17.0 - C:\Users\mynameistito\node_modules\.bin\npm.EXE
pnpm: 11.3.0 - C:\Users\mynameistito\.local\share\pnpm\bin\pnpm.CMD
bun: 1.3.14 - C:\Users\mynameistito\.bun\bin\bun.EXE
Deno: 2.8.3 - C:\Users\mynameistito\node_modules\.bin\deno.EXE
npmPackages:
@cloudflare/vite-plugin: ^1.41.0 => 1.41.0
wrangler: ^4.101.0 => 4.101.0
### Please provide a link to a minimal reproduction
https://github.com/mynameistito/workers-preview-alias-repro
### Describe the Bug
Workers Builds provides WORKERS_CI_BRANCH, but using it directly as a preview alias can fail for normal branch names that contain /.
Repro:
https://github.com/mynameistito/workers-preview-alias-repro/pull/1
Steps:
1. Set up a Worker with Workers Builds.
2. Enable non-production branch builds.
3. Use a branch like:
chore/simplify-wrangler-deploy
4. Set the non-production deploy command to:
bunx wrangler versions upload --preview-alias "${WORKERS_CI_BRANCH}"
5. Run the build.
The deploy fails because WORKERS_CI_BRANCH is passed through as:
chore/simplify-wrangler-deploy
Wrangler rejects that alias:
validation failures: invalid alias: chore/simplify-wrangler-deploy [code: 10021]
I expected this to either work out of the box, or for Workers Builds to provide a sanitized branch alias that can be passed to --preview-alias.
Current workaround is to sanitize the branch manually before calling Wrangler:
ALIAS="$(printf '%s' "$WORKERS_CI_BRANCH" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9_-]+/-/g; s/-+/-/g; s/^-+//; s/-+$//' | cut -c1-63)" && bunx wrangler versions upload --preview-alias "${ALIAS:-preview}"
Tested with Wrangler 4.101.0.
### Please provide any relevant error logs
_No response_
Contributor guide
Research direction
Start with the `wrangler versions upload --preview-alias` entry point and reproduce the failure using the linked Workers Builds example with a branch name containing `/`. Trace where the preview alias is validated, then verify that the intended handling of such branch names is covered by a regression check and that the command no longer fails unexpectedly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- cli, cloud
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100