From 6c3565c909c87dab3ed68484335a4fc3f25c69f2 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Sat, 8 Feb 2025 09:27:12 -0500 Subject: [PATCH] duckdb: fix update script to use nix-prefetch-github --- pkgs/development/libraries/duckdb/update.sh | 43 +++++++-------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/pkgs/development/libraries/duckdb/update.sh b/pkgs/development/libraries/duckdb/update.sh index 925d7f6be1a8..c440e2d5b1e2 100755 --- a/pkgs/development/libraries/duckdb/update.sh +++ b/pkgs/development/libraries/duckdb/update.sh @@ -1,18 +1,10 @@ #!/usr/bin/env nix-shell -#!nix-shell --pure -i bash -p cacert curl jq moreutils nix-prefetch +#!nix-shell -i bash -p cacert jq git moreutils nix nix-prefetch-github # shellcheck shell=bash set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" -nixpkgs=$( - while [[ ! -e .git ]]; do - [[ ${PWD} != / ]] || exit 1 - cd .. - done - echo "${PWD}" -) - repo=duckdb owner=duckdb @@ -21,34 +13,25 @@ msg() { } json_get() { - jq -r "$1" < 'versions.json' + jq -r "$1" < ./versions.json } json_set() { - jq --arg x "$2" "$1 = \$x" < 'versions.json' | sponge 'versions.json' + jq --arg x "$2" "$1 = \$x" < ./versions.json | sponge 'versions.json' } get_latest() { - curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} -s \ - "https://api.github.com/repos/${owner}/${repo}/releases/latest" | jq -r .tag_name + gh release --repo "${owner}/${repo}" list \ + --exclude-pre-releases \ + --limit 1 \ + --json tagName \ + --jq '.[].tagName' } -get_sha() { - curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} -s \ - "https://api.github.com/repos/${owner}/${repo}/git/ref/tags/$1" | jq -r .object.sha -} +tag="$(get_latest | sed 's/^v//g')" -tag=$(get_latest) -version=${tag/v/} +json=$(nix-prefetch-github "${owner}" "${repo}" --rev "v${tag}") -[[ ${version} == $(json_get .version) ]] && { - msg "${version} is up to date" - exit 0 -} - -sha=$(get_sha "${tag}") -sri=$(nix-prefetch -I nixpkgs="${nixpkgs}" -E "duckdb.overrideAttrs { version = \"${version}\"; }") - -json_set ".version" "${version}" -json_set ".rev" "${sha}" -json_set ".hash" "${sri}" +json_set ".version" "${tag}" +json_set ".rev" "$(jq -r '.rev' <<< "${json}")" +json_set ".hash" "$(jq -r '.hash' <<< "${json}")"