fix(jobPatched) Fixed some attributes not being passed into ci

Fixed modifying continuous integration settings attributes only when the job is configured via nix,
plus improved tests for this functionality.
This commit is contained in:
Skryta Istota 2025-11-30 12:55:22 +01:00
parent d2f8a70675
commit 0f9d0aae60
No known key found for this signature in database
2 changed files with 29 additions and 33 deletions

View file

@ -11,13 +11,11 @@ in
pipelineName, pipelineName,
nixConfig, nixConfig,
}: }:
if ! nixConfig.enable then job else
(builtins.removeAttrs job [ "variables" "cache" ]) (builtins.removeAttrs job [ "variables" "cache" ])
// (optionalAttrs nixConfig.enable ( // (prependToBeforeScript [ "source setup_nix_ci \"gitlab-ci:pipeline:${pipelineName}:job-deps:${key}\"" ] job)
(prependToBeforeScript ["source setup_nix_ci \"gitlab-ci:pipeline:${pipelineName}:job-deps:${key}\""] job)
// (appendToAfterScript [ "finalize_nix_ci" ] job) // (appendToAfterScript [ "finalize_nix_ci" ] job)
)) // (let
// optionalAttrs nixConfig.enable (
(let
variables = job.variables or {} // variables = job.variables or {} //
optionalAttrs nixConfig.enableRunnerCache { optionalAttrs nixConfig.enableRunnerCache {
NIX_CI_CACHE_STRATEGY = "runner"; NIX_CI_CACHE_STRATEGY = "runner";
@ -28,9 +26,8 @@ in
inherit variables; inherit variables;
}) })
// (let // (let
cache = cache = (toList (job.cache or [])) ++
(toList (job.cache or [])) (optional nixConfig.enableRunnerCache {
++ (optional nixConfig.enableRunnerCache {
key = nixConfig.runnerCacheKey; key = nixConfig.runnerCacheKey;
paths = [ ".nix-cache/" ]; paths = [ ".nix-cache/" ];
}); });
@ -39,4 +36,3 @@ in
optionalAttrs (cache != []) { optionalAttrs (cache != []) {
inherit cache; inherit cache;
}) })
)

View file

@ -57,14 +57,14 @@
{ {
name = "jobPatched nix disabled"; name = "jobPatched nix disabled";
expected = { expected = {
/*cache = [{ cache = [{
name = "some"; name = "some";
paths = [ "this" ]; paths = [ "this" ];
}]; }];
variables = { variables = {
BASH = toString pkgs.bash; BASH = toString pkgs.bash;
TEST = "work"; TEST = "work";
};*/ };
}; };
actual = mkJobPatched { actual = mkJobPatched {
key = "test"; key = "test";
@ -206,14 +206,14 @@
before_script = [ "./init" ]; before_script = [ "./init" ];
script = [ "echo Hello World!" ]; script = [ "echo Hello World!" ];
after_script = [ "./clean" ]; after_script = [ "./clean" ];
/*cache = [{ cache = [{
key = "simple"; key = "simple";
paths = [ "~/random/" ]; paths = [ "~/random/" ];
}]; }];
variables = { variables = {
SAMPLE = "working"; SAMPLE = "working";
HELLO = toString pkgs.hello; HELLO = toString pkgs.hello;
};*/ };
}; };
}; };
actual = (mkPipeline { actual = (mkPipeline {