2025-05-22 17:02:06 +01:00
|
|
|
{
|
|
|
|
nix,
|
|
|
|
writeShellApplication,
|
|
|
|
}:
|
|
|
|
writeShellApplication {
|
|
|
|
name = "update";
|
|
|
|
|
|
|
|
runtimeInputs = [
|
|
|
|
nix
|
|
|
|
];
|
|
|
|
|
|
|
|
text = ''
|
|
|
|
commit=
|
|
|
|
use_github_output=
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
--commit) commit=1
|
|
|
|
;;
|
|
|
|
--github-output) use_github_output=1
|
|
|
|
;;
|
|
|
|
--*) echo "unknown option $1"
|
|
|
|
;;
|
|
|
|
*) echo "unexpected argument $1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
update_args=( )
|
|
|
|
if [ -n "$commit" ]; then
|
|
|
|
update_args+=( "--commit-lock-file" )
|
|
|
|
fi
|
|
|
|
|
2025-06-05 11:18:40 +01:00
|
|
|
currentCommit() {
|
|
|
|
git show --no-patch --format=%h
|
|
|
|
}
|
|
|
|
|
|
|
|
hasChanges() {
|
|
|
|
old="$1"
|
|
|
|
new="$2"
|
|
|
|
if [ -n "$commit" ]; then
|
|
|
|
[ "$old" != "$new" ]
|
|
|
|
elif git diff --quiet; then
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2025-05-22 17:02:06 +01:00
|
|
|
writeGitHubOutput() {
|
2025-06-05 11:18:40 +01:00
|
|
|
if [ -n "$use_github_output" ] && [ -n "$commit" ]; then
|
|
|
|
{
|
2025-05-22 17:02:06 +01:00
|
|
|
echo "$1<<EOF"
|
|
|
|
git show --no-patch --format=%b
|
|
|
|
echo "EOF"
|
2025-06-05 11:18:40 +01:00
|
|
|
} >> "$GITHUB_OUTPUT"
|
2025-05-22 17:02:06 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2025-05-22 17:15:33 +01:00
|
|
|
versionInfo() {
|
2025-06-05 11:18:40 +01:00
|
|
|
extra_args=( )
|
|
|
|
if [ "$1" = "--amend" ]; then
|
|
|
|
extra_args+=(
|
|
|
|
"--amend"
|
|
|
|
"--no-edit"
|
|
|
|
)
|
|
|
|
fi
|
|
|
|
|
2025-06-11 22:13:00 +01:00
|
|
|
nix-build ./ci -A version-info
|
2025-06-05 10:26:58 +01:00
|
|
|
./result/bin/version-info
|
2025-06-05 11:18:40 +01:00
|
|
|
|
2025-05-22 17:15:33 +01:00
|
|
|
if [ -n "$commit" ]; then
|
|
|
|
git add version-info.toml
|
2025-06-05 11:18:40 +01:00
|
|
|
git commit "''${extra_args[@]}"
|
2025-05-22 17:15:33 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialise version-info.toml
|
|
|
|
if [ ! -f version-info.toml ]; then
|
|
|
|
echo "Creating version-info file"
|
|
|
|
versionInfo -m "version-info: init"
|
|
|
|
fi
|
|
|
|
|
2025-05-22 17:02:06 +01:00
|
|
|
# Update the root lockfile
|
2025-06-05 11:18:40 +01:00
|
|
|
old=$(currentCommit)
|
2025-05-22 17:02:06 +01:00
|
|
|
echo "Updating root lockfile"
|
|
|
|
nix flake update "''${update_args[@]}"
|
2025-06-05 11:18:40 +01:00
|
|
|
new=$(currentCommit)
|
|
|
|
if hasChanges "$old" "$new"; then
|
2025-05-22 17:15:33 +01:00
|
|
|
echo "Updating version-info"
|
2025-06-05 11:18:40 +01:00
|
|
|
versionInfo --amend
|
2025-05-22 17:02:06 +01:00
|
|
|
writeGitHubOutput root_lock_body
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Update the dev lockfile
|
|
|
|
root_nixpkgs=$(nix eval --raw --file . 'inputs.nixpkgs.rev')
|
2025-06-05 11:18:40 +01:00
|
|
|
old=$(currentCommit)
|
2025-05-22 17:02:06 +01:00
|
|
|
echo "Updating dev lockfile"
|
|
|
|
nix flake update "''${update_args[@]}" \
|
|
|
|
--override-input 'dev-nixpkgs' "github:NixOS/nixpkgs/$root_nixpkgs" \
|
|
|
|
--flake './flake/dev'
|
2025-06-05 11:18:40 +01:00
|
|
|
new=$(currentCommit)
|
|
|
|
if hasChanges "$old" "$new"; then
|
2025-05-22 17:15:33 +01:00
|
|
|
echo "Updating version-info"
|
2025-06-05 11:18:40 +01:00
|
|
|
versionInfo --amend
|
2025-05-22 17:02:06 +01:00
|
|
|
writeGitHubOutput dev_lock_body
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
}
|