about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/tools/build-managers/gradle/update.sh
blob: 03c914bbdaf4e965e7e03ce500edb12a47987b07 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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