nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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
13for v in $(curl -s "https://api.github.com/repos/gradle/gradle/releases" | jq -r '.[].tag_name' | sort -n -r)
14do
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 [[ -n "$1" && "$1" != "$v" ]]
39 then
40 echo "$v SKIP (nomatch)"
41 continue
42 elif [ "$1" == "" ] && [ -f "$f" ]
43 then
44 echo "$v SKIP (exists)"
45 continue
46 fi
47
48 url="https://services.gradle.org/distributions/gradle-${v}-bin.zip"
49 read -d "\n" gradle_hash gradle_path < <(nix-prefetch-url --print-path $url)
50
51 # Prefix and suffix for "native-platform" dependency.
52 gradle_native_prefix="gradle-$v/lib/native-platform-"
53 gradle_native_suffix=".jar"
54 tmp=$(mktemp)
55 zipinfo -1 "$gradle_path" "$gradle_native_prefix*$gradle_native_suffix" > $tmp
56 gradle_native=$(cat $tmp | head -n1)
57 gradle_native=${gradle_native#"$gradle_native_prefix"}
58 gradle_native=${gradle_native%"$gradle_native_suffix"}
59
60 # Supported architectures
61 #grep -Pho "(linux|osx)-\w+" $tmp | sort | uniq
62 rm -f $tmp
63
64 echo -e "{\\n version = \"$v\";\\n nativeVersion = \"$gradle_native\";\\n sha256 = \"$gradle_hash\";\\n}" > $f
65
66 echo "$v DONE"
67done