anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / applications / networking / cluster / timoni / update.sh
blob4e997beeece5c7683973386566d74e41a1d5dea7
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl gnused nix jq
3 set -euo pipefail
5 PKG_DIR=$(dirname "${BASH_SOURCE[@]}")
6 FILE="$PKG_DIR/default.nix"
7 NIXPKGS_ROOT=$(cd $PKG_DIR && git rev-parse --show-toplevel)
8 ATTR="timoni"
10 PREV_VERSION=$(nix eval --raw -f $NIXPKGS_ROOT/default.nix $ATTR.version)
11 LATEST_TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/stefanprodan/timoni/releases/latest | jq -r '.tag_name')
12 NEXT_VERSION=$(echo ${LATEST_TAG} | sed 's/^v//')
14 # update version
15 sed -i "s|$PREV_VERSION|$NEXT_VERSION|" "$FILE"
17 # update hash
18 PREV_HASH=$(nix eval --raw -f $NIXPKGS_ROOT/default.nix $ATTR.src.outputHash)
19 NEXT_HASH=$(nix hash to-sri --type sha256 $(nix-prefetch-url --unpack --type sha256 $(nix eval --raw -f $NIXPKGS_ROOT/default.nix $ATTR.src.url)))
20 sed -i "s|$PREV_HASH|$NEXT_HASH|" "$FILE"
22 # update vendor hash
23 PREV_VENDOR_HASH=$(nix eval --raw -f $NIXPKGS_ROOT/default.nix $ATTR.vendorHash)
24 EMPTY_HASH="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
25 sed -i "s|$PREV_VENDOR_HASH|$EMPTY_HASH|" "$FILE"
27 set +e
28 NEXT_VENDOR_HASH=$(nix-build $NIXPKGS_ROOT --no-out-link -A $ATTR 2>&1 | grep "got:" | cut -d':' -f2 | sed 's| ||g')
29 set -e
31 if [ -z "${NEXT_VENDOR_HASH:-}" ]; then
32 echo "Update failed. NEXT_VENDOR_HASH is empty." >&2
33 exit 1
36 sed -i "s|$EMPTY_HASH|$NEXT_VENDOR_HASH|" "$FILE"
38 cat <<EOF
40 "attrPath": "$ATTR",
41 "oldVersion": "$PREV_VERSION",
42 "newVersion": "$NEXT_VERSION",
43 "files": ["$PWD/default.nix.nix"]
45 EOF