biglybt: 3.5.0.0 -> 3.6.0.0
[NixPkgs.git] / pkgs / development / tools / build-managers / scala-cli / update.nix
blobfd79a1cf3a8b99d123b7d807c065d86805c8ea09
1 { lib, curl, writeShellScript, jq, gnused, git, nix, coreutils }: { platforms, pname, version }:
3 writeShellScript "${pname}-update-script" ''
4   set -o errexit
5   PATH=${lib.makeBinPath [ curl jq gnused git nix coreutils ]}
7   latest_version=$(curl -s "https://api.github.com/repos/VirtusLab/scala-cli/releases?per_page=1" | jq ".[0].tag_name" --raw-output | sed 's/^v//')
9   if [[ "${version}" = "$latest_version" ]]; then
10       echo "The new version same as the old version."
11       exit 0
12   fi
14   nixpkgs=$(git rev-parse --show-toplevel)
15   sources_json="$nixpkgs/pkgs/development/tools/build-managers/scala-cli/sources.json"
17   platform_assets=()
19   for platform in ${lib.concatStringsSep " " platforms}; do
20     asset=$(jq ".assets.\"$platform\".asset" --raw-output < $sources_json)
21     release_asset_url="https://github.com/Virtuslab/scala-cli/releases/download/v$latest_version/$asset"
23     asset_hash=$(nix-prefetch-url "$release_asset_url")
25     asset_object=$(jq --compact-output --null-input \
26       --arg asset "$asset" \
27       --arg sha256 "$asset_hash" \
28       --arg platform "$platform" \
29       '{asset: $asset, sha256: $sha256, platform: $platform}')
30     platform_assets+=($asset_object)
31   done
33   printf '%s\n' "''${platform_assets[@]}" | \
34     jq -s "map ( { (.platform): . | del(.platform) }) | add" | \
35     jq --arg version $latest_version \
36       '{ version: $version, assets: . }' > $sources_json