Cloudflare DevelopersCD
Cloudflare Developersโ€ข4mo agoโ€ข
11 replies
Hugo

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"


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! ๐Ÿ™‚
Was this page helpful?