From 32371a323f24fe27c0d3bee21daa1fcdabf1c291 Mon Sep 17 00:00:00 2001 From: Jan Votava Date: Fri, 28 Jul 2023 13:26:26 +0700 Subject: [PATCH] timoni: add update script --- .../networking/cluster/timoni/default.nix | 2 + .../networking/cluster/timoni/update.sh | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 pkgs/applications/networking/cluster/timoni/update.sh diff --git a/pkgs/applications/networking/cluster/timoni/default.nix b/pkgs/applications/networking/cluster/timoni/default.nix index c0616c6ea395..6a11965d4aa1 100644 --- a/pkgs/applications/networking/cluster/timoni/default.nix +++ b/pkgs/applications/networking/cluster/timoni/default.nix @@ -23,6 +23,8 @@ buildGoModule rec { # Some tests require running Kubernetes instance doCheck = false; + passthru.updateScript = ./update.sh; + ldflags = [ "-s" "-w" diff --git a/pkgs/applications/networking/cluster/timoni/update.sh b/pkgs/applications/networking/cluster/timoni/update.sh new file mode 100755 index 000000000000..4e997beeece5 --- /dev/null +++ b/pkgs/applications/networking/cluster/timoni/update.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl gnused nix jq +set -euo pipefail + +PKG_DIR=$(dirname "${BASH_SOURCE[@]}") +FILE="$PKG_DIR/default.nix" +NIXPKGS_ROOT=$(cd $PKG_DIR && git rev-parse --show-toplevel) +ATTR="timoni" + +PREV_VERSION=$(nix eval --raw -f $NIXPKGS_ROOT/default.nix $ATTR.version) +LATEST_TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/stefanprodan/timoni/releases/latest | jq -r '.tag_name') +NEXT_VERSION=$(echo ${LATEST_TAG} | sed 's/^v//') + +# update version +sed -i "s|$PREV_VERSION|$NEXT_VERSION|" "$FILE" + +# update hash +PREV_HASH=$(nix eval --raw -f $NIXPKGS_ROOT/default.nix $ATTR.src.outputHash) +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))) +sed -i "s|$PREV_HASH|$NEXT_HASH|" "$FILE" + +# update vendor hash +PREV_VENDOR_HASH=$(nix eval --raw -f $NIXPKGS_ROOT/default.nix $ATTR.vendorHash) +EMPTY_HASH="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" +sed -i "s|$PREV_VENDOR_HASH|$EMPTY_HASH|" "$FILE" + +set +e +NEXT_VENDOR_HASH=$(nix-build $NIXPKGS_ROOT --no-out-link -A $ATTR 2>&1 | grep "got:" | cut -d':' -f2 | sed 's| ||g') +set -e + +if [ -z "${NEXT_VENDOR_HASH:-}" ]; then + echo "Update failed. NEXT_VENDOR_HASH is empty." >&2 + exit 1 +fi + +sed -i "s|$EMPTY_HASH|$NEXT_VENDOR_HASH|" "$FILE" + +cat <