+url_status=$(curl --silent --head --location --output /dev/null --write-out \
+ '%{http_code}' "$DOWNLOAD_URL")
+if [[ $url_status = 2* ]]; then
+ echo "Artifact at DOWNLOAD_URL exists"
+else
+ echo "Artifact at DOWNLOAD_URL does not exist"
+ exit 1
+fi
+
+
+# Packaging logic needs a tarball, but can repackage a zip into tar.gz
+# if needed. All builds except multipatch-test publish both a tar.gz and zip.
+# Autorelease passes DOWNLOAD_URL to zip, others typically use tar.gz.
+# If URL is to zip, check if there's a tar.gz available to avoid repackaging.
+if [[ $DOWNLOAD_URL = *.zip ]]; then
+ # shellcheck disable=SC2154
+ candidate_tarball_url="${DOWNLOAD_URL//zip/tar.gz}"
+ # shellcheck disable=SC2154
+ url_status=$(curl --silent --head --location --output /dev/null --write-out \
+ '%{http_code}' "$candidate_tarball_url")
+ if [[ $url_status = 2* ]]; then
+ DOWNLOAD_URL="$candidate_tarball_url"
+ fi
+fi