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