exit on failure, add per-class logging
All checks were successful
Check Nix flake / Perform Nix flake checks (ubuntu-latest) (pull_request) Successful in 3m26s
Check flake.lock / Check health of `flake.lock` (pull_request) Successful in 20s
Check Nix flake / Build nix outputs (ubuntu-latest) (pull_request) Successful in 2m21s
Check Nix formatting / Perform Nix format checks (pull_request) Successful in 1m41s

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
2025-03-26 11:22:29 -04:00
parent 4438e93037
commit 607f3f9f76
5 changed files with 42 additions and 31 deletions

View File

@ -12,6 +12,7 @@ output_regexes = [
re.compile(r"checking derivation (.*)..."),
re.compile(r"checking NixOS configuration \'(nixosConfigurations.*)\'\.\.\."),
]
logger = logging.getLogger(__name__)
def traverse_json_base(json_dict: dict[str, typing.Any], path: list[str]) -> list[str]:
@ -54,7 +55,7 @@ def get_derivations_from_check(nix_path: str, path_to_flake: str) -> list[str]:
"""
flake_check = bash_wrapper(f"{nix_path} flake check --verbose --keep-going", path=path_to_flake)
if flake_check[2] != 0:
logging.warning(
logger.warning(
"nix flake check returned non-zero exit code, collecting all available outputs"
)
error_out = flake_check[1].split("\n")
@ -62,10 +63,10 @@ def get_derivations_from_check(nix_path: str, path_to_flake: str) -> list[str]:
derivations = []
for output in possible_outputs:
for r in output_regexes:
logging.debug(f"{output} {r.pattern}")
logger.debug(f"{output} {r.pattern}")
match = r.match(output)
if match is not None:
logging.debug(match.groups())
logger.debug(match.groups())
derivations += [match.groups()[0]]
return derivations
@ -84,8 +85,8 @@ def get_derivations(path_to_flake: str) -> list[str]:
raise RuntimeError(status_msg)
flake_show = bash_wrapper(f"{nix_path} flake show --json", path=path_to_flake)
if flake_show[2] != 0:
logging.error("flake show returned non-zero exit code")
logging.warning("falling back to full evaluation via nix flake check")
logger.error("flake show returned non-zero exit code")
logger.warning("falling back to full evaluation via nix flake check")
derivations = get_derivations_from_check(nix_path, path_to_flake)
else:
flake_show_json = json.loads(flake_show[0])