graalvm*-ce: improve update.sh script

This commit is contained in:
Thiago Kenji Okada 2023-02-15 21:07:41 +00:00
parent 76e8420cf8
commit 1e39bda357

View File

@ -6,6 +6,8 @@ set -eou pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
tmpfile="$(mktemp --suffix=.nix)"
trap 'rm -rf "$tmpfile"' EXIT
info() { echo "[INFO] $*"; }
echo_file() { echo "$@" >> "$tmpfile"; }
@ -59,7 +61,7 @@ readonly platforms=(
"17-darwin-amd64"
)
info "Generating hashes.nix file for 'graalvm-ce' $new_version. This will take a while..."
info "Generating '$hashes_nix' file for 'graalvm-ce' $new_version. This will take a while..."
# Indentation of `echo_file` function is on purpose to make it easier to visualize the output
echo_file "# Generated by $0 script"
@ -68,14 +70,16 @@ for product in "${!products_urls[@]}"; do
url="${products_urls["${product}"]}"
echo_file " \"$product\" = {"
for platform in "${platforms[@]}"; do
# Reuse cache as long the version is the same
if [[ "$current_version" == "$new_version" ]]; then
previous_hash="$(nix-instantiate --eval "$hashes_nix" -A "$product.$platform.sha256" --json | jq -r || true)"
args=("${url//@platform@/$platform}")
# Get current hashes to skip derivations already in /nix/store to reuse cache when the version is the same
# e.g.: when adding a new product and running this script with FORCE=1
if [[ "$current_version" == "$new_version" ]] && \
previous_hash="$(nix-instantiate --eval "$hashes_nix" -A "$product.$platform.sha256" --json | jq -r)"; then
args+=("$previous_hash" "--type" "sha256")
else
previous_hash=""
info "Hash in '$product' for '$platform' not found. Re-downloading it..."
fi
# Lack of quoting in $previous_hash is proposital
if hash="$(nix-prefetch-url "${url//@platform@/$platform}" $previous_hash)"; then
if hash="$(nix-prefetch-url "${args[@]}")"; then
echo_file " \"$platform\" = {"
echo_file " sha256 = \"$hash\";"
echo_file " url = \"${url//@platform@/${platform}}\";"