aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/pkgs/applications/version-management/sourcehut/update.sh
blob: 156d4cc35e4484c95f472dcd7e8f96ca3ea86cd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p git mercurial common-updater-scripts

cd "$(dirname "${BASH_SOURCE[0]}")"
root=../../../..

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() {
  (cd "$root" && nix-instantiate --eval --strict -A "sourcehut.python.pkgs.$1.src.drvAttrs.url" | tr -d '"')
}

get_latest_version() {
  src="$(src_url "$1")"
  tmp=$(mktemp -d)

  if [ "$1" = "hgsrht" ]; then
    hg clone "$src" "$tmp" &> /dev/null
    printf "%s" "$(cd "$tmp" && hg log --limit 1 --template '{latesttag}')"
  else
    git clone "$src" "$tmp"
    printf "%s" "$(cd "$tmp" && git describe $(git rev-list --tags --max-count=1))"
  fi
}

update_version() {
  default_nix="$(default "$1")"
  version_old="$(version "$1")"
  version="$(get_latest_version "$1")"

  (cd "$root" && update-source-version "sourcehut.python.pkgs.$1" "$version")

  git add "$default_nix"
  git commit -m "$1: $version_old -> $version"
}

services=( "srht" "buildsrht" "dispatchsrht" "gitsrht" "hgsrht" "hubsrht" "listssrht" "mansrht"
           "metasrht" "pastesrht" "todosrht" "scmsrht" )

# Whether or not a specific service is requested
if [ -n "$1" ]; then
  version="$(get_latest_version "$1")"
  (cd "$root" && update-source-version "sourcehut.python.pkgs.$1" "$version")
else
  for service in "${services[@]}"; do
    update_version "$service"
  done
fi