added tool for checking deployment requirement
All checks were successful
/ test (push) Successful in 42s
All checks were successful
/ test (push) Successful in 42s
This commit is contained in:
parent
7e7384464a
commit
a784b12962
1 changed files with 44 additions and 0 deletions
44
.forgejo/workflows/needs-deploy.sh
Executable file
44
.forgejo/workflows/needs-deploy.sh
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Check for hostname argument
|
||||
if [[ $# -ne 1 ]]; then
|
||||
echo "Usage: $0 <nixos-hostname>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
HOST="$1"
|
||||
REPO_PATH="git+file://$PWD"
|
||||
|
||||
CURRENT_COMMIT=$(git rev-parse HEAD)
|
||||
PREV_COMMIT=$(git rev-parse HEAD^)
|
||||
|
||||
# Check if the host exists at the current commit
|
||||
if ! nix eval --quiet --expr "
|
||||
let
|
||||
flake = builtins.getFlake \"${REPO_PATH}?rev=${CURRENT_COMMIT}\";
|
||||
in
|
||||
builtins.hasAttr \"${HOST}\" flake.nixosConfigurations
|
||||
"; then
|
||||
echo "Error: Host '${HOST}' not found in nixosConfigurations at HEAD."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Now check for derivation change
|
||||
RESULT=$(nix eval --raw --expr "
|
||||
let
|
||||
flake = builtins.getFlake;
|
||||
prev = flake \"${REPO_PATH}?rev=${PREV_COMMIT}\";
|
||||
curr = flake \"${REPO_PATH}?rev=${CURRENT_COMMIT}\";
|
||||
in
|
||||
if prev.nixosConfigurations.\"${HOST}\".config.system.build.toplevel !=
|
||||
curr.nixosConfigurations.\"${HOST}\".config.system.build.toplevel
|
||||
then \"changed\" else \"unchanged\"
|
||||
")
|
||||
|
||||
# Output result
|
||||
if [[ $RESULT == "changed" ]]; then
|
||||
echo "System derivation changed for host '${HOST}' — deploy!"
|
||||
else
|
||||
echo "No change for host '${HOST}' — skip deployment."
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue