Preview deployments URLs

Hey folks, Context: I'm migrating my project from Pages to Workers (SvelteKit site). Branch control > Pull request previews: Enabled(default) Version command: npx wrangler versions upload(default) Issue: While building the preview deployment of my PR branch: invalid alias: HEAD [code: 10021] What I tried: Changing the command to get a bit more infos on what's going on:
c="${WORKERS_CI_BRANCH:-}";
g="$(git rev-parse --abbrev-ref HEAD 2>/dev/null||true)";
echo "CF_BRANCH=${c:-(empty)}";
echo "GIT_BRANCH=${g:-(none)}";
{ [ -z "$c" ]||[ "$g" = HEAD ]; }&&echo "WARNING: no branch context";
r="${c:-$g}";
a="$(printf '%s' "${r:-pr}"|tr '[:upper:]' '[:lower:]'|sed -E 's/[^a-z0-9-]+/-/g;s/^-+//;s/-+$//'|cut -c1-40)";case $a in [a-z]*) ;; *)a="b-$a";; esac;
echo "ALIAS=$a";
npx wrangler versions upload --preview-alias "$a"
c="${WORKERS_CI_BRANCH:-}";
g="$(git rev-parse --abbrev-ref HEAD 2>/dev/null||true)";
echo "CF_BRANCH=${c:-(empty)}";
echo "GIT_BRANCH=${g:-(none)}";
{ [ -z "$c" ]||[ "$g" = HEAD ]; }&&echo "WARNING: no branch context";
r="${c:-$g}";
a="$(printf '%s' "${r:-pr}"|tr '[:upper:]' '[:lower:]'|sed -E 's/[^a-z0-9-]+/-/g;s/^-+//;s/-+$//'|cut -c1-40)";case $a in [a-z]*) ;; *)a="b-$a";; esac;
echo "ALIAS=$a";
npx wrangler versions upload --preview-alias "$a"
Logs: CF_BRANCH=feat-preview-worker-2 GIT_BRANCH=HEAD WARNING: no branch context ALIAS=feat-preview-worker-2 So it seems the issue it that the git branch is not present (because CF check out the commit not the branch ?), so HEAD is taken instead, which seems to lead to the error. So far it "works" here because I write the alias here with that command, but its not the nominal way of doing I guess... Any ideas ? Thanks for your help! 🙂
10 Replies
texan
texan2mo ago
Hey @Hugo , we had a big in a previous version of workers ( I can't recall which, but I think it was 4.2X?). If you upgrade your version of wrangler to latest, you'll definitely have the fix!
Hugo
HugoOP2mo ago
Hey! Thanks for your reply 🙂 Don’t the Cloudflare remote using the latest version of Wrangler ? I do not have the wrangler lib in my dev dependencies in my package.json
texan
texan2mo ago
Hmm.. then yeah it should be picking up the latest. What do your build logs say? Code-wise, we set WORKERS_CI_BRANCH and then workers-sdk picks that up https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/versions/upload.ts#L996
GitHub
workers-sdk/packages/wrangler/src/versions/upload.ts at main · clo...
⛅️ Home to Wrangler, the CLI for Cloudflare Workers® - cloudflare/workers-sdk
Hugo
HugoOP2mo ago
Logs saying: invalid alias: HEAD [code: 10021] Using the default: npx wrangler versions upload
texan
texan2mo ago
What version of wrangler?
Hugo
HugoOP2mo ago
Oh actually it shows 4.19.1 ! I’m gonna install the latest dev dep, so it should take the version from that I guess
texan
texan2mo ago
🙂 that'll do it Report back, let me know!
Hugo
HugoOP2mo ago
It works!! Thanks for your help 🙂 Any other thing to pay attention while we are talking about Worker deployment from a Pages project ? E.g all my Rules and CF setups will works as usual as long the Worker is deployed under the domain I guess ?
Walshy
Walshy2mo ago
yep, if you already have setup done on a zone, as long as the Worker also runs in that zone, everything will run the same
Hugo
HugoOP2mo ago
Great, thanks!

Did you find this page helpful?