···11+#!/usr/bin/env nix-shell
22+#!nix-shell -i bash -p nix-prefetch curl jq
33+44+# Generates Gradle release specs from GitHub Releases.
55+#
66+# As of 2021-11, this script has very poor error handling,
77+# it is expected to be run by maintainers as one-off job
88+# only.
99+#
1010+# NOTE: The earliest Gradle release that has a
1111+# corresponding entry as GitHub Release is 6.8-rc-1.
1212+1313+for v in $(curl -s "https://api.github.com/repos/gradle/gradle/releases" | jq -r '.[].tag_name' | sort -n -r)
1414+do
1515+ # Tag names and download filenames are not the same,
1616+ # we modify the tag name slightly to translate it
1717+ # to the naming scheme of download filenames.
1818+ # This translation assumes a tag naming scheme.
1919+ # As of 2021-11 it works from 6.8-rc-1 to 7.3-rc-3.
2020+2121+ # Remove first letter (assumed to be "v").
2222+ v=${v:1}
2323+2424+ # To lower case.
2525+ v=${v,,}
2626+2727+ # Add dash after "rc".
2828+ v=${v/-rc/-rc-}
2929+3030+ # Remove trailing ".0"
3131+ v=${v%.0}
3232+3333+ # Remove trailing ".0" for release candidates.
3434+ v=${v/.0-rc/-rc}
3535+3636+ f="gradle-${v}-spec.nix"
3737+3838+ if [ -f "$f" ]
3939+ then
4040+ echo "$v SKIP"
4141+ continue
4242+ fi
4343+4444+ url="https://services.gradle.org/distributions/gradle-${v}-bin.zip"
4545+ read -d "\n" gradle_hash gradle_path < <(nix-prefetch-url --print-path $url)
4646+4747+ # Prefix and suffix for "native-platform" dependency.
4848+ gradle_native_prefix="gradle-$v/lib/native-native-"
4949+ gradle_native_suffix=".jar"
5050+ gradle_native=$(zipinfo -1 "$gradle_path" "$gradle_native_prefix*$gradle_native_suffix" | head -n1)
5151+ gradle_native=${gradle_native#"$gradle_native_prefix"}
5252+ gradle_native=${gradle_native%"$gradle_native_suffix"}
5353+5454+ echo -e "{\\n version = \"$v\";\\n nativeVersion = \"$gradle_native\";\\n sha256 = \"$gradle_hash\";\\n}" > $f
5555+5656+ echo "$v DONE"
5757+done