ironbar: 0.16.0 -> 0.16.1 (#361476)
[NixPkgs.git] / pkgs / development / tools / fable / update.sh
blob181570d1a0dee88ff9f1db01fcc6b78a4479fc1e
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl gnused nix-prefetch jq
4 set -euo pipefail
5 URL="https://github.com/fable-compiler/fable"
6 PKG="Fable"
7 ROOT="$(dirname "$(readlink -f "$0")")"
8 NIX_DRV="$ROOT/default.nix"
9 if [ ! -f "$NIX_DRV" ]; then
10 echo "ERROR: cannot find default.nix in $ROOT"
11 exit 1
14 TMP="$(mktemp -d)"
15 clean_up() {
16 rm -rf "$TMP"
18 trap clean_up EXIT SIGINT SIGTERM
19 PACKAGES="$TMP/packages"
20 SRC_RW="$TMP/src"
22 mkdir -p $SRC_RW
23 mkdir -p $PACKAGES
26 VER=$(curl -s "https://api.github.com/repos/fable-compiler/fable/releases/latest" | jq -r .tag_name | grep -oP '\d+\.\d+\.\d+' )
28 CURRENT_VER=$(grep -oP '(?<=version = ")[^"]+' "$NIX_DRV")
29 if [[ "$CURRENT_VER" == "$VER" ]]; then
30 echo "$PKG is already up to date: $CURRENT_VER"
31 exit
35 NUGET_URL="$(curl -f "https://api.nuget.org/v3/index.json" | jq --raw-output '.resources[] | select(."@type" == "PackageBaseAddress/3.0.0")."@id"')$PKG/$VER/$PKG.$VER.nupkg"
36 HASH=$(nix-hash --to-sri --type sha256 "$(nix-prefetch-url "$NUGET_URL")")
38 sed -i "s/version = \".*\"/version = \"$VER\"/" "$NIX_DRV"
39 sed -i "s#nugetHash = \"sha256-.\{44\}\"#nugetHash = \"$HASH\"#" "$NIX_DRV"