about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/tools/build-managers/gradle/update.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/tools/build-managers/gradle/update.sh')
-rwxr-xr-xnixpkgs/pkgs/development/tools/build-managers/gradle/update.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/tools/build-managers/gradle/update.sh b/nixpkgs/pkgs/development/tools/build-managers/gradle/update.sh
new file mode 100755
index 000000000000..03c914bbdaf4
--- /dev/null
+++ b/nixpkgs/pkgs/development/tools/build-managers/gradle/update.sh
@@ -0,0 +1,57 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p nix-prefetch curl jq
+
+# Generates Gradle release specs from GitHub Releases.
+#
+# As of 2021-11, this script has very poor error handling,
+# it is expected to be run by maintainers as one-off job
+# only.
+#
+# NOTE: The earliest Gradle release that has a
+# corresponding entry as GitHub Release is 6.8-rc-1.
+
+for v in $(curl -s "https://api.github.com/repos/gradle/gradle/releases" | jq -r '.[].tag_name' | sort -n -r)
+do
+    # Tag names and download filenames are not the same,
+    # we modify the tag name slightly to translate it
+    # to the naming scheme of download filenames.
+    # This translation assumes a tag naming scheme.
+    # As of 2021-11 it works from 6.8-rc-1 to 7.3-rc-3.
+
+    # Remove first letter (assumed to be "v").
+    v=${v:1}
+
+    # To lower case.
+    v=${v,,}
+
+    # Add dash after "rc".
+    v=${v/-rc/-rc-}
+
+    # Remove trailing ".0"
+    v=${v%.0}
+
+    # Remove trailing ".0" for release candidates.
+    v=${v/.0-rc/-rc}
+
+    f="gradle-${v}-spec.nix"
+
+    if [ -f "$f" ]
+    then
+        echo "$v SKIP"
+        continue
+    fi
+
+    url="https://services.gradle.org/distributions/gradle-${v}-bin.zip"
+    read -d "\n" gradle_hash gradle_path < <(nix-prefetch-url --print-path $url)
+
+    # Prefix and suffix for "native-platform" dependency.
+    gradle_native_prefix="gradle-$v/lib/native-native-"
+    gradle_native_suffix=".jar"
+    gradle_native=$(zipinfo -1 "$gradle_path" "$gradle_native_prefix*$gradle_native_suffix" | head -n1)
+    gradle_native=${gradle_native#"$gradle_native_prefix"}
+    gradle_native=${gradle_native%"$gradle_native_suffix"}
+
+    echo -e "{\\n  version = \"$v\";\\n  nativeVersion = \"$gradle_native\";\\n  sha256 = \"$gradle_hash\";\\n}" > $f
+
+    echo "$v DONE"
+done