This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / pkgs / timeful / update.sh
2.4 kB 71 lines
1#!/usr/bin/env bash 2set -euo pipefail 3 4# Three hashes move together (src, frontend npmDepsHash, server vendorHash), 5# and src is wrapped in applyPatches, so nix-update can't do this one. 6owner=schej-it 7repo=timeful.app 8branch=main 9attr=timeful 10 11# Run by update-pkgs from the flake root ($0 is a read-only store copy). 12pkg=pkgs/timeful/package.nix 13# Linux-only package: always evaluate/build the x86_64-linux variant. 14build_attr=".#packages.x86_64-linux.$attr" 15 16new_rev=$(curl -fsSL "https://api.github.com/repos/$owner/$repo/commits/$branch" | jq -r .sha) 17old_rev=$(sed -n 's|^ *rev = "\([^"]*\)";|\1|p' "$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.committer.date | cut -d T -f1) 24new_version="0-unstable-$new_date" 25 26# Portable in-place sed (BSD and GNU). 27edit() { 28 local tmp 29 tmp=$(mktemp) 30 sed "$@" "$pkg" >"$tmp" 31 cat "$tmp" >"$pkg" 32 rm -f "$tmp" 33} 34 35# Bump rev + version and blank every hash: with the old ones in place nix 36# reuses the cached FODs and the build "succeeds" on stale code. 37edit \ 38 -e "s|^\( *\)rev = \".*\";|\1rev = \"$new_rev\";|" \ 39 -e "s|^\( *\)version = \".*\";|\1version = \"$new_version\";|" \ 40 -e "s|^\( *\)hash = \".*\";|\1hash = \"\";|" \ 41 -e "s|^\( *\)npmDepsHash = \".*\";|\1npmDepsHash = \"\";|" \ 42 -e "s|^\( *\)vendorHash = \".*\";|\1vendorHash = \"\";|" 43 44update_hash() { 45 local field=$1 new=$2 46 edit -e "s|^\( *\)$field = \"[^\"]*\";|\1$field = \"$new\";|" 47} 48 49# The probe build is *expected* to fail (hash mismatch); `|| true` keeps 50# pipefail/errexit from turning that into an empty `got`. awk must not 51# `exit` early or tee dies of SIGPIPE and takes the pipeline with it. 52probe_hash() { 53 { nix build --no-link "$build_attr$1" 2>&1 || true; } | tee /dev/stderr \ 54 | awk '/got:/ && !seen { print $2; seen = 1 }' || true 55} 56 57# Probe each FOD on its own so a hash is never attributed to the wrong field. 58for spec in hash:.src npmDepsHash:.frontend.npmDeps vendorHash:.goModules; do 59 field=${spec%%:*} 60 sub=${spec#*:} 61 got=$(probe_hash "$sub") 62 if [ -z "$got" ]; then 63 echo "$attr: no hash reported for $field" >&2 64 exit 1 65 fi 66 update_hash "$field" "$got" 67 echo "$attr: $field → $got" 68done 69 70echo "$attr: updated to $new_rev ($new_version)" 71nix build --no-link "$build_attr"