forgejo-lts: 7.0.10 -> 7.0.11
[NixPkgs.git] / pkgs / applications / version-management / sourcehut / update.sh
blobe5dd0b5baed0460921121b24d1fa5950fe8f7d6d
1 #! /usr/bin/env nix-shell
2 #! nix-shell -i bash -p gnused git mercurial common-updater-scripts
3 set -eux -o pipefail
5 cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
6 root=../../../..
7 tmp=$(mktemp -d)
8 trap 'rm -rf "$tmp"' EXIT
10 attr_path() {
11 case "$1" in
12 pagessrht) printf "sourcehut.$1";;
13 *) printf "sourcehut.python.pkgs.$1";;
14 esac
17 default() {
18 local p="$(attr_path "$1")"
19 (cd "$root" && nix-instantiate --eval --strict -A $p.meta.position | sed -re 's/^"(.*):[0-9]+"$/\1/')
22 version() {
23 local p="$(attr_path "$1")"
24 (cd "$root" && nix-instantiate --eval --strict -A $p.version | tr -d '"')
27 src_url() {
28 local p="$(attr_path "$1")"
29 nix-instantiate --eval --strict --expr " with import $root {}; let src = $p.drvAttrs.src; in src.meta.homepage" | tr -d '"'
32 get_latest_version() {
33 src="$(src_url "$1")"
34 rm -rf "$tmp"
35 if [ "$1" = "hgsrht" ]; then
36 hg clone "$src" "$tmp" >/dev/null
37 printf "%s %s\n" \
38 "$(cd "$tmp" && hg log --limit 1 --template '{latesttag}')" \
39 "$(cd "$tmp" && sed -ne 's/^\s*github\.com\/99designs\/gqlgen v\(.*\)$/\1/p' go.mod)"
40 else
41 git clone "$src" "$tmp" >/dev/null
42 printf "%s %s\n" \
43 "$(cd "$tmp" && git describe "$(git rev-list --tags --max-count=1)")" \
44 "$(cd "$tmp" && sed -ne 's/^\s*github\.com\/99designs\/gqlgen v\(.*\)$/\1/p' go.mod)"
48 update_version() {
49 default_nix="$(default "$1")"
50 oldVersion="$(version "$1")"
51 read -r version gqlgen_ver < <(get_latest_version "$1")
52 local p="$(attr_path "$1")"
54 (cd "$root" && update-source-version "$p" "$version")
56 # update `gqlgenVersion` if necessary
57 old_gqlgen_ver="$(sed -ne 's/^.*gqlgenVersion = "\(.*\)".*$/\1/p' "$default_nix")"
58 sed -ri "s|gqlgenVersion = \"$old_gqlgen_ver\";|gqlgenVersion = \"$gqlgen_ver\";|w /dev/stdout" "$default_nix"
60 # Update vendorHash of Go modules
61 retry=true
62 while "$retry"; do
63 retry=false;
64 exec < <(exec nix -L build -f "$root" sourcehut.python.pkgs."$1" 2>&1)
65 while IFS=' :' read -r origin hash; do
66 case "$origin" in
67 (expected|specified) oldHash="$hash";;
68 (got) sed -i "s|$oldHash|$hash|" "$default_nix"; retry=true; break;;
69 (*) printf >&2 "%s\n" "$origin${hash:+:$hash}"
70 esac
71 done
72 done
74 if [ "$oldVersion" != "$version" ] || [ "$old_gqlgen_ver" != "$gqlgen_ver" ]; then
75 git add "$default_nix"
76 git commit -m "sourcehut.$1: $oldVersion -> $version"
80 if [ $# -gt 0 ]; then
81 services=("$@")
82 else
83 # Beware that some packages must be updated before others,
84 # eg. buildsrht must be updated before gitsrht,
85 # otherwise this script would enter an infinite loop
86 # because the reported $oldHash to be changed
87 # may not actually be in $default_nix
88 # but in the file of one of its dependencies.
89 services=( "srht" "scmsrht" "buildsrht" "gitsrht" "hgsrht" "hubsrht" "listssrht" "mansrht"
90 "metasrht" "pagessrht" "pastesrht" "todosrht" )
93 for service in "${services[@]}"; do
94 update_version "$service"
95 done