2023-02-11 14:06:18 +01:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell -p coreutils curl.out nix jq gnused -i bash
|
|
|
|
|
2023-09-26 15:24:53 +02:00
|
|
|
# Usage:
|
|
|
|
# ./update.sh [PRODUCT]
|
|
|
|
#
|
|
|
|
# Examples:
|
2023-09-28 17:03:54 +02:00
|
|
|
# $ ./update.sh graalvm-ce # will generate ./graalvm-ce/hashes.nix
|
2023-09-26 15:24:53 +02:00
|
|
|
# $ ./update.sh # same as above
|
2023-09-28 17:03:54 +02:00
|
|
|
# $ ./update.sh graalpy # will generate ./graalpy/hashes.nix
|
2023-09-26 15:24:53 +02:00
|
|
|
#
|
|
|
|
# Environment variables:
|
|
|
|
# FORCE=1 to force the update of a product (e.g.: skip up-to-date checks)
|
|
|
|
# VERSION=xx.xx will assume that xx.xx is the new version
|
|
|
|
|
2023-02-11 14:06:18 +01:00
|
|
|
set -eou pipefail
|
|
|
|
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
|
|
|
tmpfile="$(mktemp --suffix=.nix)"
|
2023-09-28 17:03:54 +02:00
|
|
|
readonly tmpfile
|
2023-02-11 14:06:18 +01:00
|
|
|
|
2023-02-15 22:07:41 +01:00
|
|
|
trap 'rm -rf "$tmpfile"' EXIT
|
|
|
|
|
2023-02-11 14:06:18 +01:00
|
|
|
info() { echo "[INFO] $*"; }
|
|
|
|
|
|
|
|
echo_file() { echo "$@" >> "$tmpfile"; }
|
|
|
|
|
|
|
|
verlte() {
|
|
|
|
[ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ]
|
|
|
|
}
|
|
|
|
|
2023-09-26 15:24:53 +02:00
|
|
|
readonly product="${1:-graalvm-ce}"
|
2023-09-26 19:49:33 +02:00
|
|
|
readonly hashes_nix="$product/hashes.nix"
|
2023-02-11 14:06:18 +01:00
|
|
|
readonly nixpkgs=../../../../..
|
|
|
|
|
2023-09-26 19:49:33 +02:00
|
|
|
mkdir -p "$product"
|
|
|
|
|
2023-09-26 15:24:53 +02:00
|
|
|
declare -r -A update_urls=(
|
|
|
|
[graalvm-ce]="https://api.github.com/repos/graalvm/graalvm-ce-builds/releases/latest"
|
2023-09-26 19:28:07 +02:00
|
|
|
[graaljs]="https://api.github.com/repos/oracle/graaljs/releases/latest"
|
2023-09-26 19:34:49 +02:00
|
|
|
[graalnodejs]="https://api.github.com/repos/oracle/graaljs/releases/latest"
|
2023-09-26 15:24:53 +02:00
|
|
|
[graalpy]="https://api.github.com/repos/oracle/graalpython/releases/latest"
|
2023-09-26 18:28:04 +02:00
|
|
|
[truffleruby]="https://api.github.com/repos/oracle/truffleruby/releases/latest"
|
2023-09-26 15:24:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
current_version="$(nix-instantiate "$nixpkgs" --eval --strict -A "graalvmCEPackages.${product}.version" --json | jq -r)"
|
|
|
|
readonly current_version
|
2023-02-11 14:06:18 +01:00
|
|
|
|
2023-09-26 15:24:53 +02:00
|
|
|
if [[ -z "${VERSION:-}" ]]; then
|
|
|
|
gh_version="$(curl \
|
2023-02-11 14:06:18 +01:00
|
|
|
${GITHUB_TOKEN:+"-u \":$GITHUB_TOKEN\""} \
|
2023-09-26 15:24:53 +02:00
|
|
|
-s "${update_urls[$product]}" | \
|
2023-02-11 14:06:18 +01:00
|
|
|
jq --raw-output .tag_name)"
|
2023-09-26 15:24:53 +02:00
|
|
|
new_version="${gh_version//jdk-/}"
|
|
|
|
new_version="${new_version//graal-/}"
|
2023-02-11 14:06:18 +01:00
|
|
|
else
|
2023-09-26 15:24:53 +02:00
|
|
|
new_version="$VERSION"
|
2023-02-11 14:06:18 +01:00
|
|
|
fi
|
2023-09-26 15:24:53 +02:00
|
|
|
readonly new_version
|
2023-02-11 14:06:18 +01:00
|
|
|
|
|
|
|
info "Current version: $current_version"
|
|
|
|
info "New version: $new_version"
|
|
|
|
if verlte "$new_version" "$current_version"; then
|
2023-09-26 15:24:53 +02:00
|
|
|
info "$product $current_version is up-to-date."
|
2023-02-11 14:06:18 +01:00
|
|
|
[[ -z "${FORCE:-}" ]] && exit 0
|
|
|
|
else
|
2023-09-26 15:24:53 +02:00
|
|
|
info "$product $current_version is out-of-date. Updating..."
|
2023-02-11 14:06:18 +01:00
|
|
|
fi
|
|
|
|
|
2023-09-26 15:24:53 +02:00
|
|
|
# Make sure to get the `-community` versions!
|
2023-02-11 14:06:18 +01:00
|
|
|
declare -r -A products_urls=(
|
graalvm-ce: 22.3.1 -> 21.0.0
This initially may look like a downgrade, but this is caused by how
upstream is tagging versions.
Before they would have the GraalVM having its own version (e.g. 22.3.1),
and each version would support multiple JVM versions (e.g. 11, 17, 19).
Now each release supports only one JVM version (e.g.: 21), and they
track the same version as the JVM.
They also changed packaging, making all sub-products (e.g.: GraalPy,
GraalRuby, etc.) standalone, so they do not depend in GraalVM anymore
and have their own version. Thanks to this change, we will need to
repackage everything.
To simplify, this commit will remove all sub-products and only care
about the GraalVM/Native Image (that is back to GraalVM itself) part.
Other commits will re-added each sub-product.
Fix (partial): https://github.com/NixOS/nixpkgs/issues/257292
2023-09-26 14:03:23 +02:00
|
|
|
[graalvm-ce]="https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-${new_version}/graalvm-community-jdk-${new_version}_@platform@_bin.tar.gz"
|
2023-09-26 19:28:07 +02:00
|
|
|
[graaljs]="https://github.com/oracle/graaljs/releases/download/graal-${new_version}/graaljs-community-${new_version}-@platform@.tar.gz"
|
2023-09-26 19:34:49 +02:00
|
|
|
[graalnodejs]="https://github.com/oracle/graaljs/releases/download/graal-${new_version}/graalnodejs-community-${new_version}-@platform@.tar.gz"
|
2023-09-26 15:24:53 +02:00
|
|
|
[graalpy]="https://github.com/oracle/graalpython/releases/download/graal-${new_version}/graalpy-community-${new_version}-@platform@.tar.gz"
|
2023-09-26 18:28:04 +02:00
|
|
|
[truffleruby]="https://github.com/oracle/truffleruby/releases/download/graal-${new_version}/truffleruby-community-${new_version}-@platform@.tar.gz"
|
2023-02-11 14:06:18 +01:00
|
|
|
)
|
|
|
|
|
2023-09-26 20:15:43 +02:00
|
|
|
# Argh, this is really inconsistent...
|
2023-09-26 15:24:53 +02:00
|
|
|
if [[ "$product" == "graalvm-ce" ]]; then
|
2023-09-26 20:15:43 +02:00
|
|
|
declare -r -A platforms=(
|
|
|
|
[aarch64-linux]="linux-aarch64"
|
|
|
|
[x86_64-linux]="linux-x64"
|
|
|
|
[aarch64-darwin]="macos-aarch64"
|
|
|
|
[x86_64-darwin]="macos-x64"
|
2023-09-26 15:24:53 +02:00
|
|
|
)
|
|
|
|
else
|
2023-09-26 20:15:43 +02:00
|
|
|
declare -r -A platforms=(
|
|
|
|
[aarch64-linux]="linux-aarch64"
|
|
|
|
[x86_64-linux]="linux-amd64"
|
|
|
|
[aarch64-darwin]="macos-aarch64"
|
|
|
|
[x86_64-darwin]="macos-amd64"
|
2023-09-26 15:24:53 +02:00
|
|
|
)
|
|
|
|
fi
|
2023-02-11 14:06:18 +01:00
|
|
|
|
2023-09-26 15:24:53 +02:00
|
|
|
info "Generating '$hashes_nix' file for '$product' $new_version. This will take a while..."
|
2023-02-11 14:06:18 +01:00
|
|
|
|
|
|
|
# Indentation of `echo_file` function is on purpose to make it easier to visualize the output
|
2023-09-28 17:03:54 +02:00
|
|
|
echo_file "# Generated by $(basename $0) script"
|
2023-02-11 14:06:18 +01:00
|
|
|
echo_file "{"
|
2023-09-26 16:26:44 +02:00
|
|
|
echo_file " \"version\" = \"$new_version\";"
|
2023-09-26 15:24:53 +02:00
|
|
|
url="${products_urls["${product}"]}"
|
2023-09-27 15:43:24 +02:00
|
|
|
echo_file " \"hashes\" = {"
|
2023-09-26 20:15:43 +02:00
|
|
|
for nix_platform in "${!platforms[@]}"; do
|
|
|
|
product_platform="${platforms[$nix_platform]}"
|
|
|
|
args=("${url//@platform@/$product_platform}")
|
2023-09-26 15:24:53 +02:00
|
|
|
# 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" ]] && \
|
2023-09-28 17:03:54 +02:00
|
|
|
previous_hash="$(nix-instantiate --eval "$hashes_nix" -A "hashes.$nix_platform.sha256" --json | jq -r)"; then
|
2023-09-26 15:24:53 +02:00
|
|
|
args+=("$previous_hash" "--type" "sha256")
|
|
|
|
else
|
2023-09-26 20:15:43 +02:00
|
|
|
info "Hash in '$product' for '$nix_platform' not found. Re-downloading it..."
|
2023-09-26 15:24:53 +02:00
|
|
|
fi
|
|
|
|
if hash="$(nix-prefetch-url "${args[@]}")"; then
|
2023-09-26 20:15:43 +02:00
|
|
|
echo_file " \"$nix_platform\" = {"
|
2023-02-11 14:06:18 +01:00
|
|
|
echo_file " sha256 = \"$hash\";"
|
2023-09-26 20:15:43 +02:00
|
|
|
echo_file " url = \"${url//@platform@/${product_platform}}\";"
|
2023-02-11 14:06:18 +01:00
|
|
|
echo_file " };"
|
2023-09-26 15:24:53 +02:00
|
|
|
else
|
2023-09-26 20:15:43 +02:00
|
|
|
info "Error while downloading '$product' for '$nix_platform'. Skipping it..."
|
2023-09-26 15:24:53 +02:00
|
|
|
fi
|
2023-02-11 14:06:18 +01:00
|
|
|
done
|
2023-09-26 15:24:53 +02:00
|
|
|
echo_file " };"
|
2023-02-11 14:06:18 +01:00
|
|
|
echo_file "}"
|
|
|
|
|
2023-09-26 15:24:53 +02:00
|
|
|
info "Moving the temporary file to '$hashes_nix'"
|
2023-02-14 16:17:12 +01:00
|
|
|
mv "$tmpfile" "$hashes_nix"
|
2023-02-11 14:06:18 +01:00
|
|
|
|
|
|
|
info "Done!"
|