packages/pin: add update-all subcommand

This commit is contained in:
Max Headroom 2022-08-30 20:49:05 +02:00
parent 14b9c287f5
commit 2eca973488
2 changed files with 20 additions and 8 deletions

View file

@ -1,6 +1,6 @@
{ {
writeShellApplication, writeShellApplication,
nix, npins nix, npins, jq
}: }:
writeShellApplication { writeShellApplication {
@ -8,6 +8,7 @@ writeShellApplication {
runtimeInputs = [ runtimeInputs = [
nix nix
npins npins
jq
]; ];
text = builtins.readFile ./pin.sh; text = builtins.readFile ./pin.sh;
} }

View file

@ -1,17 +1,28 @@
REPO_ROOT="${REPO_ROOT:-.}" REPO_ROOT="${REPO_ROOT:-.}"
NPINS_DIRECTORY="${NPINS_DIRECTORY:-npins}" NPINS_DIRECTORY="${NPINS_DIRECTORY:-npins}"
cmd_update() {
for pkg in "$@"; do
oldver=$(nix eval --raw "${REPO_ROOT}#${pkg}.version")
npins update "$pkg"
newver=$(nix eval --raw "${REPO_ROOT}#${pkg}.version")
git add "${NPINS_DIRECTORY}"
git commit "${NPINS_DIRECTORY}" -m "packages/$pkg: $oldver -> $newver" || true
done
}
cmd_update_all() {
# shellcheck disable=SC2046
cmd_update $(jq < "${NPINS_DIRECTORY}/sources.json" -r '.pins | keys | .[]')
}
cmd="$1" cmd="$1"
shift shift
case $cmd in case $cmd in
update) update)
for pkg in "$@"; do cmd_update "$@";;
oldver=$(nix eval --raw "${REPO_ROOT}#${pkg}.version") update-all)
npins update "$pkg" cmd_update_all "$@";;
newver=$(nix eval --raw "${REPO_ROOT}#${pkg}.version")
git add "${NPINS_DIRECTORY}"
git commit "${NPINS_DIRECTORY}" -m "packages/$pkg: $oldver -> $newver"
done;;
*) *)
echo Unknown command: "$cmd";; echo Unknown command: "$cmd";;
esac esac