mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +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:
parent
a1817d1c0e
commit
37fec70bd5
2 changed files with 65 additions and 74 deletions
|
|
@ -1,73 +1,58 @@
|
|||
{
|
||||
lib ? import ../../modules/lib/stdlib-extended.nix (import <nixpkgs> { }).lib,
|
||||
changedFilesJson ? throw "provide either changedFiles or changedFilesJson",
|
||||
changedFiles ? builtins.fromJSON changedFilesJson,
|
||||
file ? throw "provide file argument",
|
||||
}:
|
||||
let
|
||||
config = { };
|
||||
releaseInfo = lib.importJSON ../../release.json;
|
||||
|
||||
extractMaintainersFromFile =
|
||||
file:
|
||||
let
|
||||
isNixFile = lib.hasSuffix ".nix" file;
|
||||
filePath = ../../. + "/${file}";
|
||||
fileExists = builtins.pathExists filePath;
|
||||
isNixFile = lib.hasSuffix ".nix" file;
|
||||
filePath = ../../. + "/${file}";
|
||||
fileExists = builtins.pathExists filePath;
|
||||
|
||||
moduleResult =
|
||||
if isNixFile && fileExists then
|
||||
let
|
||||
result = builtins.tryEval (
|
||||
let
|
||||
fileContent = import filePath;
|
||||
maintainers =
|
||||
if isNixFile && fileExists then
|
||||
let
|
||||
fileContent = import filePath;
|
||||
|
||||
module =
|
||||
if lib.isFunction fileContent then
|
||||
# TODO: Find a better way of handling this...
|
||||
if lib.hasPrefix "docs/" file then
|
||||
if lib.hasSuffix "home-manager-manual.nix" file then
|
||||
fileContent {
|
||||
stdenv = {
|
||||
mkDerivation = x: x;
|
||||
};
|
||||
inherit lib;
|
||||
documentation-highlighter = { };
|
||||
revision = "unknown";
|
||||
home-manager-options = {
|
||||
home-manager = { };
|
||||
nixos = { };
|
||||
nix-darwin = { };
|
||||
};
|
||||
nixos-render-docs = { };
|
||||
}
|
||||
else
|
||||
fileContent {
|
||||
inherit lib;
|
||||
pkgs = null;
|
||||
inherit (releaseInfo) release isReleaseBranch;
|
||||
}
|
||||
else if lib.hasPrefix "lib/" file then
|
||||
fileContent { inherit lib; }
|
||||
else
|
||||
fileContent {
|
||||
inherit lib config;
|
||||
pkgs = null;
|
||||
}
|
||||
else
|
||||
fileContent;
|
||||
in
|
||||
module.meta.maintainers or [ ]
|
||||
else
|
||||
[ ];
|
||||
|
||||
module =
|
||||
if lib.isFunction fileContent then
|
||||
# TODO: Find a better way of handling this...
|
||||
if lib.hasPrefix "docs/" file then
|
||||
if lib.hasSuffix "home-manager-manual.nix" file then
|
||||
fileContent {
|
||||
stdenv = {
|
||||
mkDerivation = x: x;
|
||||
};
|
||||
inherit lib;
|
||||
documentation-highlighter = { };
|
||||
revision = "unknown";
|
||||
home-manager-options = {
|
||||
home-manager = { };
|
||||
nixos = { };
|
||||
nix-darwin = { };
|
||||
};
|
||||
nixos-render-docs = { };
|
||||
}
|
||||
else
|
||||
fileContent {
|
||||
inherit lib;
|
||||
pkgs = null;
|
||||
inherit (releaseInfo) release isReleaseBranch;
|
||||
}
|
||||
else if lib.hasPrefix "lib/" file then
|
||||
fileContent { inherit lib; }
|
||||
else
|
||||
fileContent {
|
||||
inherit lib config;
|
||||
pkgs = null;
|
||||
}
|
||||
else
|
||||
fileContent;
|
||||
in
|
||||
module.meta.maintainers or [ ]
|
||||
);
|
||||
in
|
||||
if result.success then result.value else [ ]
|
||||
else
|
||||
[ ];
|
||||
in
|
||||
moduleResult;
|
||||
in
|
||||
lib.pipe changedFiles [
|
||||
(map extractMaintainersFromFile)
|
||||
lib.concatLists
|
||||
lib.unique
|
||||
(map (maintainer: maintainer.github))
|
||||
]
|
||||
map (maintainer: maintainer.github) maintainers
|
||||
|
|
|
|||
|
|
@ -55,19 +55,25 @@ def extract_maintainers(changed_files: list[str], pr_author: str) -> list[str]:
|
|||
|
||||
logging.info("Finding maintainers for changed files...")
|
||||
nix_file = Path(__file__).parent.parent / "nix" / "extract-maintainers.nix"
|
||||
changed_files_json = json.dumps(changed_files)
|
||||
|
||||
try:
|
||||
result_json = run_nix_eval(nix_file, "--argstr", "changedFilesJson", changed_files_json)
|
||||
maintainers = set(json.loads(result_json))
|
||||
except NixEvalError:
|
||||
# Error is already logged by run_nix_eval
|
||||
return []
|
||||
except json.JSONDecodeError as e:
|
||||
logging.error(f"Error parsing JSON output from Nix: {e}")
|
||||
return []
|
||||
all_maintainers = set()
|
||||
|
||||
filtered_maintainers = sorted(list(maintainers - {pr_author}))
|
||||
for file in changed_files:
|
||||
try:
|
||||
result_json = run_nix_eval(nix_file, "--argstr", "file", file)
|
||||
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:
|
||||
# Error is already logged by run_nix_eval, just skip this file
|
||||
logging.debug(f"Skipping {file} due to evaluation error")
|
||||
continue
|
||||
except json.JSONDecodeError as e:
|
||||
logging.error(f"Error parsing JSON output from Nix for {file}: {e}")
|
||||
continue
|
||||
|
||||
filtered_maintainers = sorted(list(all_maintainers - {pr_author}))
|
||||
|
||||
if not filtered_maintainers:
|
||||
logging.info("No maintainers found (or only the PR author is a maintainer).")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue