2023-02-11 13:06:18 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell -p coreutils curl.out nix jq gnused -i bash
|
|
|
|
|
|
|
|
set -eou pipefail
|
|
|
|
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
|
|
|
tmpfile="$(mktemp --suffix=.nix)"
|
|
|
|
|
2023-02-15 21:07:41 +00:00
|
|
|
trap 'rm -rf "$tmpfile"' EXIT
|
|
|
|
|
2023-02-11 13:06:18 +00:00
|
|
|
info() { echo "[INFO] $*"; }
|
|
|
|
|
|
|
|
echo_file() { echo "$@" >> "$tmpfile"; }
|
|
|
|
|
|
|
|
verlte() {
|
|
|
|
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
|
|
|
|
}
|
|
|
|
|
2023-02-14 15:17:12 +00:00
|
|
|
readonly hashes_nix="hashes.nix"
|
2023-02-11 13:06:18 +00:00
|
|
|
readonly nixpkgs=../../../../..
|
|
|
|
|
2023-02-14 15:17:12 +00:00
|
|
|
readonly current_version="$(nix-instantiate "$nixpkgs" --eval --strict -A graalvm-ce.version --json | jq -r)"
|
2023-02-11 13:06:18 +00:00
|
|
|
|
|
|
|
if [[ -z "${1:-}" ]]; then
|
|
|
|
readonly gh_version="$(curl \
|
|
|
|
${GITHUB_TOKEN:+"-u \":$GITHUB_TOKEN\""} \
|
|
|
|
-s https://api.github.com/repos/graalvm/graalvm-ce-builds/releases/latest | \
|
|
|
|
jq --raw-output .tag_name)"
|
|
|
|
readonly new_version="${gh_version//vm-/}"
|
|
|
|
else
|
|
|
|
readonly new_version="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
info "Current version: $current_version"
|
|
|
|
info "New version: $new_version"
|
|
|
|
if verlte "$new_version" "$current_version"; then
|
|
|
|
info "graalvm-ce $current_version is up-to-date."
|
|
|
|
[[ -z "${FORCE:-}" ]] && exit 0
|
|
|
|
else
|
|
|
|
info "graalvm-ce $current_version is out-of-date. Updating..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
declare -r -A products_urls=(
|
|
|
|
[graalvm-ce]="https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/graalvm-ce-java@platform@-${new_version}.tar.gz"
|
2023-02-14 17:19:52 +00:00
|
|
|
[js-installable-svm]="https://github.com/graalvm/graaljs/releases/download/vm-${new_version}/js-installable-svm-java@platform@-${new_version}.jar"
|
2023-02-14 15:23:26 +00:00
|
|
|
[llvm-installable-svm]="https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/llvm-installable-svm-java@platform@-${new_version}.jar"
|
2023-02-11 13:06:18 +00:00
|
|
|
[native-image-installable-svm]="https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/native-image-installable-svm-java@platform@-${new_version}.jar"
|
2023-02-15 21:53:52 +00:00
|
|
|
[nodejs-installable-svm]="https://github.com/graalvm/graaljs/releases/download/vm-${new_version}/nodejs-installable-svm-java@platform@-${new_version}.jar"
|
2023-02-14 15:17:12 +00:00
|
|
|
[python-installable-svm]="https://github.com/graalvm/graalpython/releases/download/vm-${new_version}/python-installable-svm-java@platform@-${new_version}.jar"
|
2023-02-13 20:59:33 +00:00
|
|
|
[ruby-installable-svm]="https://github.com/oracle/truffleruby/releases/download/vm-${new_version}/ruby-installable-svm-java@platform@-${new_version}.jar"
|
|
|
|
[wasm-installable-svm]="https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${new_version}/wasm-installable-svm-java@platform@-${new_version}.jar"
|
2023-02-11 13:06:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
readonly platforms=(
|
|
|
|
"11-linux-aarch64"
|
|
|
|
"17-linux-aarch64"
|
2023-02-21 12:54:27 +00:00
|
|
|
"19-linux-aarch64"
|
2023-02-11 13:06:18 +00:00
|
|
|
"11-linux-amd64"
|
|
|
|
"17-linux-amd64"
|
2023-02-21 12:54:27 +00:00
|
|
|
"19-linux-amd64"
|
2023-02-11 13:06:18 +00:00
|
|
|
"11-darwin-aarch64"
|
|
|
|
"17-darwin-aarch64"
|
2023-02-21 12:54:27 +00:00
|
|
|
"19-darwin-aarch64"
|
2023-02-11 13:06:18 +00:00
|
|
|
"11-darwin-amd64"
|
|
|
|
"17-darwin-amd64"
|
2023-02-21 12:54:27 +00:00
|
|
|
"19-darwin-amd64"
|
2023-02-11 13:06:18 +00:00
|
|
|
)
|
|
|
|
|
2023-02-15 21:07:41 +00:00
|
|
|
info "Generating '$hashes_nix' file for 'graalvm-ce' $new_version. This will take a while..."
|
2023-02-11 13:06:18 +00:00
|
|
|
|
|
|
|
# Indentation of `echo_file` function is on purpose to make it easier to visualize the output
|
|
|
|
echo_file "# Generated by $0 script"
|
|
|
|
echo_file "{"
|
|
|
|
for product in "${!products_urls[@]}"; do
|
|
|
|
url="${products_urls["${product}"]}"
|
|
|
|
echo_file " \"$product\" = {"
|
|
|
|
for platform in "${platforms[@]}"; do
|
2023-02-15 21:07:41 +00:00
|
|
|
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")
|
2023-02-14 15:17:12 +00:00
|
|
|
else
|
2023-02-15 21:07:41 +00:00
|
|
|
info "Hash in '$product' for '$platform' not found. Re-downloading it..."
|
2023-02-14 15:17:12 +00:00
|
|
|
fi
|
2023-02-15 21:07:41 +00:00
|
|
|
if hash="$(nix-prefetch-url "${args[@]}")"; then
|
2023-02-11 13:06:18 +00:00
|
|
|
echo_file " \"$platform\" = {"
|
|
|
|
echo_file " sha256 = \"$hash\";"
|
|
|
|
echo_file " url = \"${url//@platform@/${platform}}\";"
|
|
|
|
echo_file " };"
|
2023-02-14 15:17:12 +00:00
|
|
|
else
|
|
|
|
info "Error while downloading '$product' for '$platform'. Skipping it..."
|
2023-02-11 13:06:18 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo_file " };"
|
|
|
|
done
|
|
|
|
echo_file "}"
|
|
|
|
|
|
|
|
info "Updating graalvm-ce version..."
|
|
|
|
# update-source-version does not work here since it expects src attribute
|
|
|
|
sed "s|$current_version|$new_version|" -i default.nix
|
|
|
|
|
|
|
|
info "Moving the temporary file to hashes.nix"
|
2023-02-14 15:17:12 +00:00
|
|
|
mv "$tmpfile" "$hashes_nix"
|
2023-02-11 13:06:18 +00:00
|
|
|
|
|
|
|
info "Done!"
|