···1+#!/usr/bin/env nix-shell
2+#!nix-shell -i bash -p nix-prefetch curl jq
3+4+# Generates Gradle release specs from GitHub Releases.
5+#
6+# As of 2021-11, this script has very poor error handling,
7+# it is expected to be run by maintainers as one-off job
8+# only.
9+#
10+# NOTE: The earliest Gradle release that has a
11+# corresponding entry as GitHub Release is 6.8-rc-1.
12+13+for v in $(curl -s "https://api.github.com/repos/gradle/gradle/releases" | jq -r '.[].tag_name' | sort -n -r)
14+do
15+ # Tag names and download filenames are not the same,
16+ # we modify the tag name slightly to translate it
17+ # to the naming scheme of download filenames.
18+ # This translation assumes a tag naming scheme.
19+ # As of 2021-11 it works from 6.8-rc-1 to 7.3-rc-3.
20+21+ # Remove first letter (assumed to be "v").
22+ v=${v:1}
23+24+ # To lower case.
25+ v=${v,,}
26+27+ # Add dash after "rc".
28+ v=${v/-rc/-rc-}
29+30+ # Remove trailing ".0"
31+ v=${v%.0}
32+33+ # Remove trailing ".0" for release candidates.
34+ v=${v/.0-rc/-rc}
35+36+ f="gradle-${v}-spec.nix"
37+38+ if [ -f "$f" ]
39+ then
40+ echo "$v SKIP"
41+ continue
42+ fi
43+44+ url="https://services.gradle.org/distributions/gradle-${v}-bin.zip"
45+ read -d "\n" gradle_hash gradle_path < <(nix-prefetch-url --print-path $url)
46+47+ # Prefix and suffix for "native-platform" dependency.
48+ gradle_native_prefix="gradle-$v/lib/native-native-"
49+ gradle_native_suffix=".jar"
50+ gradle_native=$(zipinfo -1 "$gradle_path" "$gradle_native_prefix*$gradle_native_suffix" | head -n1)
51+ gradle_native=${gradle_native#"$gradle_native_prefix"}
52+ gradle_native=${gradle_native%"$gradle_native_suffix"}
53+54+ echo -e "{\\n version = \"$v\";\\n nativeVersion = \"$gradle_native\";\\n sha256 = \"$gradle_hash\";\\n}" > $f
55+56+ echo "$v DONE"
57+done