This repository has no description
1.6 kB
56 lines
1#!/usr/bin/env bash
2set -euo pipefail
3
4# Tracks upstream Mic92/main.
5owner=Mic92
6repo=tincr
7branch=main
8attr=tincr
9
10pkg="$(dirname "$(realpath "$0")")/package.nix"
11
12cd "$(dirname "$(realpath "$0")")"
13while [ ! -e flake.nix ] && [ "$PWD" != / ]; do cd ..; done
14system=$(nix eval --raw --impure --expr 'builtins.currentSystem')
15
16new_rev=$(curl -fsSL "https://api.github.com/repos/$owner/$repo/commits/$branch" | jq -r .sha)
17old_rev=$(grep -oP '^\s*rev = "\K[^"]+' "$pkg")
18if [ "$old_rev" = "$new_rev" ]; then
19 echo "$attr: already up to date ($new_rev)"
20 exit 0
21fi
22
23new_date=$(curl -fsSL "https://api.github.com/repos/$owner/$repo/commits/$new_rev" | jq -r .commit.author.date | cut -d T -f1)
24new_version="0-unstable-$new_date"
25
26# Bump rev + version, leave hashes for nix to complain about.
27sed -i \
28 -e "s|^\(\s*\)rev = \".*\"|\1rev = \"$new_rev\"|" \
29 -e "s|^\(\s*\)version = \".*\"|\1version = \"$new_version\"|" \
30 "$pkg"
31
32# Each FOD reports its own hash on first miss; build twice (src, then vendor).
33extract_got() {
34 awk '/got:/{print $2; exit}'
35}
36update_hash() {
37 local field=$1 new=$2
38 sed -i "s|^\(\s*\)$field = \"[^\"]*\"|\1$field = \"$new\"|" "$pkg"
39}
40
41build_attr=".#packages.$system.$attr"
42
43if got=$(nix build --no-link "$build_attr" 2>&1 | tee /dev/stderr | extract_got) \
44 && [ -n "$got" ]; then
45 update_hash hash "$got"
46 echo "$attr: src hash → $got"
47fi
48
49if got=$(nix build --no-link "$build_attr" 2>&1 | tee /dev/stderr | extract_got) \
50 && [ -n "$got" ]; then
51 update_hash cargoHash "$got"
52 echo "$attr: cargoHash → $got"
53fi
54
55echo "$attr: updated to $new_rev ($new_version)"
56nix build --no-link "$build_attr"