Add update script for heartwood version and flake

Use this script to update tests/support/heartwood-version and keep the
flake in sync with it.

Alternatively, run the script as

    scripts/update-flake $(cat tests/support/heartwood-version)

to bring the flake back into sync.

This also updates the flake.lock and the updates the state of the npm
dependencies when run from a nix-enabled system.
This commit is contained in:
Michael Raitza
2024-02-05 15:05:32 +01:00
committed by Sebastian Martinez
parent 1324c8e320
commit 414c6cafda
3 changed files with 94 additions and 19 deletions
+75
View File
@@ -0,0 +1,75 @@
#!/bin/sh
set -e
usage() {
printf \
'Update flake and heartwood-version to the requested heartwood version.
When called without arguments, reads HASH from tests/support/hearwood-version.
USAGE:
update-flake [-h] [PATH|HASH]
OPTIONS:
PATH\t\tPath to heartwood git repo; uses current HEAD.
HASH\t\tUpdate heartwood version to HASH.
-h --help\tPrint this help.\n'
}
while [ $# -ne 0 ]; do
case $1 in
--help | -h)
usage >&2
exit
;;
*/*)
hash=$(git -C "$1" rev-parse --verify HEAD)
shift
;;
*)
hash=$1
shift
;;
esac
done
# Heartwood repo id
rid=z3gqcJUoA1n9HaHKufZs5FCSGazv5
# Some root detection guess work...
root=$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD")
if [ ! -e "$root/tests/support/heartwood-version" ]; then
root=$(cd .. ; pwd)
fi
if [ -z "$hash" ]; then
# No hash given, take from heartwood-version
if [ -e "$root/tests/support/heartwood-version" ]; then
hash=$(cat "$root/tests/support/heartwood-version")
[ -n "$hash" ] || {
printf "Error reading heartwood-version\n" >&2
exit 1
}
fi
else
printf '%s\n' "$hash" >$root/tests/support/heartwood-version
fi
if [ -e "$root/flake.nix" ]; then
sed -E -e '/url.*git\+https.*'"$rid"'/s/(rev=)[0-9a-f]{40,40}/\1'"$hash"'/' "$root/flake.nix" >$root/flake.nix.tmp
mv "$root/flake.nix.tmp" "$root/flake.nix"
# If running on a nix-enabled system, also update npmDepsHash.
if type nix >/dev/null 2>&1; then
npmDepsHash=$(nix --experimental-features 'nix-command flakes' \
run --inputs-from "$root" nixpkgs#prefetch-npm-deps \
-- "$root/package-lock.json")
sed -E -e '/npmDepsHash/s/".*"/"'"$npmDepsHash"'"/' "$root/flake.nix" >$root/flake.nix.tmp
mv "$root/flake.nix.tmp" "$root/flake.nix"
nix --experimental-features 'nix-command flakes' flake update "$root"
else
printf >&2 'Node dependencies may be out of date!
Re-run on a nix-enabled system to update npmDepsHash.\n'
fi
fi