1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-14 13:01:09 +01:00

ci: extract maintainers with single file eval (#7548)

Currently, we send all files as a list but it can be problematic with
files that can't be evaluated properly. Instead of crashing the entire
extraction process, we will send a file at a time for eval so we can
just bypass files causing issues.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
Austin Horstman 2025-07-26 13:26:14 -05:00 committed by GitHub
parent a1817d1c0e
commit 37fec70bd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 65 additions and 74 deletions

View file

@ -1,23 +1,17 @@
{ {
lib ? import ../../modules/lib/stdlib-extended.nix (import <nixpkgs> { }).lib, lib ? import ../../modules/lib/stdlib-extended.nix (import <nixpkgs> { }).lib,
changedFilesJson ? throw "provide either changedFiles or changedFilesJson", file ? throw "provide file argument",
changedFiles ? builtins.fromJSON changedFilesJson,
}: }:
let let
config = { }; config = { };
releaseInfo = lib.importJSON ../../release.json; releaseInfo = lib.importJSON ../../release.json;
extractMaintainersFromFile =
file:
let
isNixFile = lib.hasSuffix ".nix" file; isNixFile = lib.hasSuffix ".nix" file;
filePath = ../../. + "/${file}"; filePath = ../../. + "/${file}";
fileExists = builtins.pathExists filePath; fileExists = builtins.pathExists filePath;
moduleResult = maintainers =
if isNixFile && fileExists then if isNixFile && fileExists then
let
result = builtins.tryEval (
let let
fileContent = import filePath; fileContent = import filePath;
@ -57,17 +51,8 @@ let
fileContent; fileContent;
in in
module.meta.maintainers or [ ] module.meta.maintainers or [ ]
);
in
if result.success then result.value else [ ]
else else
[ ]; [ ];
in in
moduleResult; map (maintainer: maintainer.github) maintainers
in
lib.pipe changedFiles [
(map extractMaintainersFromFile)
lib.concatLists
lib.unique
(map (maintainer: maintainer.github))
]

View file

@ -55,19 +55,25 @@ def extract_maintainers(changed_files: list[str], pr_author: str) -> list[str]:
logging.info("Finding maintainers for changed files...") logging.info("Finding maintainers for changed files...")
nix_file = Path(__file__).parent.parent / "nix" / "extract-maintainers.nix" nix_file = Path(__file__).parent.parent / "nix" / "extract-maintainers.nix"
changed_files_json = json.dumps(changed_files)
all_maintainers = set()
for file in changed_files:
try: try:
result_json = run_nix_eval(nix_file, "--argstr", "changedFilesJson", changed_files_json) result_json = run_nix_eval(nix_file, "--argstr", "file", file)
maintainers = set(json.loads(result_json)) file_maintainers = json.loads(result_json)
all_maintainers.update(file_maintainers)
if file_maintainers:
logging.debug(f"Found maintainers for {file}: {file_maintainers}")
except NixEvalError: except NixEvalError:
# Error is already logged by run_nix_eval # Error is already logged by run_nix_eval, just skip this file
return [] logging.debug(f"Skipping {file} due to evaluation error")
continue
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
logging.error(f"Error parsing JSON output from Nix: {e}") logging.error(f"Error parsing JSON output from Nix for {file}: {e}")
return [] continue
filtered_maintainers = sorted(list(maintainers - {pr_author})) filtered_maintainers = sorted(list(all_maintainers - {pr_author}))
if not filtered_maintainers: if not filtered_maintainers:
logging.info("No maintainers found (or only the PR author is a maintainer).") logging.info("No maintainers found (or only the PR author is a maintainer).")