This repository has no description
2.2 kB
69 lines
1#!/usr/bin/env bash
2set -euo pipefail
3
4# Tracks our fork's integration branch (Mic92/tincr#101 + #109); switch back to
5# Mic92/main once merged.
6owner=Lassulus
7repo=tincr
8branch=lassulus/fixes
9attr=tincr
10
11pkg="$(dirname "$(realpath "$0")")/package.nix"
12
13cd "$(dirname "$(realpath "$0")")"
14while [ ! -e flake.nix ] && [ "$PWD" != / ]; do cd ..; done
15system=$(nix eval --raw --impure --expr 'builtins.currentSystem')
16
17new_rev=$(curl -fsSL "https://api.github.com/repos/$owner/$repo/commits/$branch" | jq -r .sha)
18old_rev=$(grep -oP '^\s*rev = "\K[^"]+' "$pkg")
19if [ "$old_rev" = "$new_rev" ]; then
20 echo "$attr: already up to date ($new_rev)"
21 exit 0
22fi
23
24new_date=$(curl -fsSL "https://api.github.com/repos/$owner/$repo/commits/$new_rev" | jq -r .commit.author.date | cut -d T -f1)
25new_version="0-unstable-$new_date"
26
27# Bump rev + version, leave hashes for nix to complain about.
28# Blank both hashes too: with the old ones in place nix reuses the cached
29# FODs (old src + old vendor dir) and the build "succeeds" on stale code.
30sed -i \
31 -e "s|^\(\s*\)rev = \".*\"|\1rev = \"$new_rev\"|" \
32 -e "s|^\(\s*\)version = \".*\"|\1version = \"$new_version\"|" \
33 -e "s|^\(\s*\)hash = \".*\"|\1hash = \"\"|" \
34 -e "s|^\(\s*\)cargoHash = \".*\"|\1cargoHash = \"\"|" \
35 "$pkg"
36
37# Each FOD reports its own hash on first miss; build twice (src, then vendor).
38extract_got() {
39 awk '/got:/{print $2; exit}'
40}
41update_hash() {
42 local field=$1 new=$2
43 sed -i "s|^\(\s*\)$field = \"[^\"]*\"|\1$field = \"$new\"|" "$pkg"
44}
45
46build_attr=".#packages.$system.$attr"
47
48# The probe build is *expected* to fail (hash mismatch); `|| true` keeps
49# pipefail/errexit from turning that into an empty `got`. awk must not
50# `exit` early or tee dies of SIGPIPE and takes the pipeline with it.
51probe_hash() {
52 { nix build --no-link "$build_attr" 2>&1 || true; } | tee /dev/stderr \
53 | awk '/got:/ && !seen { print $2; seen = 1 }' || true
54}
55
56got=$(probe_hash)
57if [ -n "$got" ]; then
58 update_hash hash "$got"
59 echo "$attr: src hash → $got"
60fi
61
62got=$(probe_hash)
63if [ -n "$got" ]; then
64 update_hash cargoHash "$got"
65 echo "$attr: cargoHash → $got"
66fi
67
68echo "$attr: updated to $new_rev ($new_version)"
69nix build --no-link "$build_attr"