2020-04-24 23:36:52 +00:00
|
|
|
#! /usr/bin/env nix-shell
|
|
|
|
#! nix-shell -i bash -p git mercurial common-updater-scripts
|
2021-12-30 13:39:12 +00:00
|
|
|
set -eux -o pipefail
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-30 13:39:12 +00:00
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
|
2020-04-24 23:36:52 +00:00
|
|
|
root=../../../..
|
2021-12-30 13:39:12 +00:00
|
|
|
tmp=$(mktemp -d)
|
|
|
|
trap 'rm -rf "$tmp"' EXIT
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
default() {
|
|
|
|
(cd "$root" && nix-instantiate --eval --strict -A "sourcehut.python.pkgs.$1.meta.position" | sed -re 's/^"(.*):[0-9]+"$/\1/')
|
|
|
|
}
|
|
|
|
|
|
|
|
version() {
|
|
|
|
(cd "$root" && nix-instantiate --eval --strict -A "sourcehut.python.pkgs.$1.version" | tr -d '"')
|
|
|
|
}
|
|
|
|
|
|
|
|
src_url() {
|
2022-06-16 17:23:12 +00:00
|
|
|
nix-instantiate --eval --strict --expr " with import $root {}; let src = sourcehut.python.pkgs.$1.drvAttrs.src; in src.meta.homepage" | tr -d '"'
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get_latest_version() {
|
|
|
|
src="$(src_url "$1")"
|
2021-12-30 13:39:12 +00:00
|
|
|
rm -rf "$tmp"
|
2020-04-24 23:36:52 +00:00
|
|
|
if [ "$1" = "hgsrht" ]; then
|
2021-12-30 13:39:12 +00:00
|
|
|
hg clone "$src" "$tmp" >/dev/null
|
2020-04-24 23:36:52 +00:00
|
|
|
printf "%s" "$(cd "$tmp" && hg log --limit 1 --template '{latesttag}')"
|
|
|
|
else
|
2021-12-30 13:39:12 +00:00
|
|
|
git clone "$src" "$tmp" >/dev/null
|
|
|
|
printf "%s" "$(cd "$tmp" && git describe "$(git rev-list --tags --max-count=1)")"
|
2020-04-24 23:36:52 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
update_version() {
|
|
|
|
default_nix="$(default "$1")"
|
2021-12-30 13:39:12 +00:00
|
|
|
oldVersion="$(version "$1")"
|
2020-04-24 23:36:52 +00:00
|
|
|
version="$(get_latest_version "$1")"
|
|
|
|
|
|
|
|
(cd "$root" && update-source-version "sourcehut.python.pkgs.$1" "$version")
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
# Update vendorHash of Go modules
|
2021-12-30 13:39:12 +00:00
|
|
|
retry=true
|
|
|
|
while "$retry"; do
|
|
|
|
retry=false;
|
|
|
|
exec < <(exec nix -L build -f "$root" sourcehut.python.pkgs."$1" 2>&1)
|
|
|
|
while IFS=' :' read -r origin hash; do
|
|
|
|
case "$origin" in
|
|
|
|
(expected|specified) oldHash="$hash";;
|
|
|
|
(got) sed -i "s|$oldHash|$hash|" "$default_nix"; retry=true; break;;
|
|
|
|
(*) printf >&2 "%s\n" "$origin${hash:+:$hash}"
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
done
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-30 13:39:12 +00:00
|
|
|
if [ "$oldVersion" != "$version" ]; then
|
|
|
|
git add "$default_nix"
|
|
|
|
git commit -m "sourcehut.$1: $oldVersion -> $version"
|
|
|
|
fi
|
|
|
|
}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-12-30 13:39:12 +00:00
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
services=("$@")
|
2020-04-24 23:36:52 +00:00
|
|
|
else
|
2021-12-30 13:39:12 +00:00
|
|
|
# Beware that some packages must be updated before others,
|
|
|
|
# eg. buildsrht must be updated before gitsrht,
|
|
|
|
# otherwise this script would enter an infinite loop
|
|
|
|
# because the reported $oldHash to be changed
|
|
|
|
# may not actually be in $default_nix
|
|
|
|
# but in the file of one of its dependencies.
|
2022-12-02 08:20:57 +00:00
|
|
|
services=( "srht" "scmsrht" "buildsrht" "gitsrht" "hgsrht" "hubsrht" "listssrht" "mansrht"
|
2021-12-30 13:39:12 +00:00
|
|
|
"metasrht" "pagessrht" "pastesrht" "todosrht" )
|
2020-04-24 23:36:52 +00:00
|
|
|
fi
|
2021-12-30 13:39:12 +00:00
|
|
|
|
|
|
|
for service in "${services[@]}"; do
|
|
|
|
update_version "$service"
|
|
|
|
done
|