<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
#!/usr/bin/env bash
set -eo pipefail

if [[ -z "$AZURE_STORAGE_CONNECTION_STRING" ]]; then
	echo "AZURE_STORAGE_CONNECTION_STRING is required"
	exit 1
fi

if [[ -z "$CONTAINER_NAME" ]]; then
	echo "CONTAINER_NAME is required"
	exit 1
fi

if [[ -z "$BLOB_NAME" ]]; then
		echo "BLOB_NAME is required"
		exit 1
fi

if [[ "$SUDO" = true ]]; then
	SUDO_COMMAND=(sudo)
else
	SUDO_COMMAND=()
fi

CACHE_PATH=${CACHE_PATH:-$BLOB_NAME}


echo "--> Checking whether blob exists"
EXISTS=$(
	az storage blob exists \
	--container-name "$CONTAINER_NAME" \
	--name "$BLOB_NAME" \
	--connection-string "$AZURE_STORAGE_CONNECTION_STRING" \
	--output tsv
)
echo "$EXISTS"

if [[ "$EXISTS" = True ]]; then
	echo "--> Downloading and extracting blob"
	mkdir -p "$CACHE_PATH"
	if az storage blob download \
		--container-name "$CONTAINER_NAME" \
		--name "$BLOB_NAME" \
		--no-progress \
		| "${SUDO_COMMAND[@]}" env ZSTD_NBTHREADS=0 tar -C "$CACHE_PATH" -x --zstd -f -; then
	    echo "Extracted"

	    echo "cache-hit=true" >> "$GITHUB_OUTPUT"
        else
            echo "azure blob is probably corrupted, deleting it..."
            az storage blob delete \
		--container-name "$CONTAINER_NAME" \
		--name "$BLOB_NAME"
            echo "cache-hit=false" >> "$GITHUB_OUTPUT"
        fi
else
	echo "cache-hit=false" >> "$GITHUB_OUTPUT"
fi
