Compare commits

...

7 commits

Author SHA1 Message Date
Skryta Istota
bdbc12771f Merge branch 'fix-job-patch' into 'main'
fix: weird jobs patching

See merge request TECHNOFAB/nix-gitlab-ci!15
2025-12-02 14:32:22 +01:00
Skryta Istota
fc79dd5120
chore(cilib_test) Improved tests for generating cache settings
Changed tests for generating cache configurations to consider single settings for ci.
2025-11-30 14:44:44 +01:00
Skryta Istota
8487c78246
fix(ci) Fixed downloading images from project forks for ci
Improved container image location guessing for repository forks.
2025-11-30 14:14:14 +01:00
Skryta Istota
0f9d0aae60
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.
2025-11-30 12:55:22 +01:00
Skryta Istota
d2f8a70675
fix(jobPatched) Removed too frequent filtering of variables
Removed excessive disposal of environment variables containing paths to nix store package files,
plus improved tests for this functionality.
2025-11-30 12:46:50 +01:00
Skryta Istota
f84edb7760
fix(storeDir) Use the builtin nix store location indicator
Minor fixes in the variable filtering function with nix packages.
2025-11-30 11:44:23 +01:00
Skryta Istota
58a0db7861
tests(cilib_test) Extended test definition for the ci lib
Extended the definition of tests for the continuous integration library,
allowing for more in-depth testing of odd behavior of some library functions.
2025-11-30 11:22:55 +01:00
2 changed files with 190 additions and 59 deletions

View file

@ -3,7 +3,7 @@
helpers,
}: let
inherit (lib) toList optionalAttrs optional;
inherit (helpers) prependToBeforeScript appendToAfterScript filterJobVariables;
inherit (helpers) prependToBeforeScript appendToAfterScript;
in
{
key,
@ -11,16 +11,13 @@ in
pipelineName,
nixConfig,
}:
(builtins.removeAttrs job ["variables" "cache"])
// (optionalAttrs nixConfig.enable (
(prependToBeforeScript ["source setup_nix_ci \"gitlab-ci:pipeline:${pipelineName}:job-deps:${key}\""] job)
// (appendToAfterScript ["finalize_nix_ci"] job)
))
// optionalAttrs nixConfig.enable (
(let
variables =
(filterJobVariables false job)
// optionalAttrs nixConfig.enableRunnerCache {
if ! nixConfig.enable then job else
(builtins.removeAttrs job [ "variables" "cache" ])
// (prependToBeforeScript [ "source setup_nix_ci \"gitlab-ci:pipeline:${pipelineName}:job-deps:${key}\"" ] job)
// (appendToAfterScript [ "finalize_nix_ci" ] job)
// (let
variables = job.variables or {} //
optionalAttrs nixConfig.enableRunnerCache {
NIX_CI_CACHE_STRATEGY = "runner";
};
in
@ -29,15 +26,13 @@ in
inherit variables;
})
// (let
cache =
(toList (job.cache or []))
++ (optional nixConfig.enableRunnerCache {
cache = (toList (job.cache or [])) ++
(optional nixConfig.enableRunnerCache {
key = nixConfig.runnerCacheKey;
paths = [".nix-cache/"];
paths = [ ".nix-cache/" ];
});
in
# filter empty cache
optionalAttrs (cache != []) {
inherit cache;
})
)

View file

@ -56,24 +56,59 @@
}
{
name = "jobPatched nix disabled";
expected = {};
expected = {
cache = {
name = "some";
paths = [ "this" ];
};
variables = {
BASH = toString pkgs.bash;
TEST = "work";
};
};
actual = mkJobPatched {
key = "test";
pipelineName = "test";
job = {};
job = {
cache = {
name = "some";
paths = [ "this" ];
};
variables = {
BASH = toString pkgs.bash;
TEST = "work";
};
};
nixConfig.enable = false;
};
}
{
name = "jobPatched without runner cache";
expected = {
after_script = ["finalize_nix_ci"];
before_script = ["source setup_nix_ci \"gitlab-ci:pipeline:test:job-deps:test\""];
after_script = [ "finalize_nix_ci" ];
before_script = [ "source setup_nix_ci \"gitlab-ci:pipeline:test:job-deps:test\"" ];
variables = {
BASH = toString pkgs.bash;
TEST = "work";
};
cache = [{
name = "some";
paths = [ "this" ];
}];
};
actual = mkJobPatched {
key = "test";
pipelineName = "test";
job = {};
job = {
cache = {
name = "some";
paths = [ "this" ];
};
variables = {
BASH = toString pkgs.bash;
TEST = "work";
};
};
nixConfig = {
enable = true;
enableRunnerCache = false;
@ -83,20 +118,34 @@
{
name = "jobPatched with runner cache";
expected = {
after_script = ["finalize_nix_ci"];
before_script = ["source setup_nix_ci \"gitlab-ci:pipeline:test:job-deps:test\""];
cache = [
{
after_script = [ "finalize_nix_ci" ];
before_script = [ "source setup_nix_ci \"gitlab-ci:pipeline:test:job-deps:test\"" ];
cache = [{
name = "some";
paths = [ "this" ];
}{
key = "test";
paths = [".nix-cache/"];
}
];
variables."NIX_CI_CACHE_STRATEGY" = "runner";
paths = [ ".nix-cache/" ];
}];
variables = {
NIX_CI_CACHE_STRATEGY = "runner";
BASH = toString pkgs.bash;
TEST = "work";
};
};
actual = mkJobPatched {
key = "test";
pipelineName = "test";
job = {};
job = {
cache = {
name = "some";
paths = [ "this" ];
};
variables = {
BASH = toString pkgs.bash;
TEST = "work";
};
};
nixConfig = {
enable = true;
enableRunnerCache = true;
@ -145,20 +194,107 @@
'';
}
{
name = "handle store paths in variables";
name = "handle store paths in variables without nix config";
expected = {
stages = ["test"];
test.stage = "test";
stages = [ "test" ];
variables = {
EXAMPLE = "empty";
CURL = toString pkgs.curl;
};
actual =
(mkPipeline {
test = {
stage = "test";
before_script = [ "./init" ];
script = [ "echo Hello World!" ];
after_script = [ "./clean" ];
cache = {
key = "simple";
paths = [ "~/random/" ];
};
variables = {
SAMPLE = "working";
HELLO = toString pkgs.hello;
};
};
};
actual = (mkPipeline {
name = "test";
nixConfig.enable = false;
pipeline = {
stages = ["test"];
stages = [ "test" ];
variables = {
EXAMPLE = "empty";
CURL = toString pkgs.curl;
};
jobs.test = {
stage = "test";
variables."TEST" = "${pkgs.hello}";
before_script = [ "./init" ];
script = [ "echo Hello World!" ];
after_script = [ "./clean" ];
cache = {
key = "simple";
paths = [ "~/random/" ];
};
variables = {
SAMPLE = "working";
HELLO = toString pkgs.hello;
};
};
};
}).finalConfig;
}
{
name = "handle store paths in variables with nix config";
expected = {
stages = [ "test" ];
variables = {
EXAMPLE = "empty";
CURL = toString pkgs.curl;
};
test = {
stage = "test";
before_script = [ "source setup_nix_ci \"gitlab-ci:pipeline:test:job-deps:test\"" "./init" ];
script = [ "echo Hello World!" ];
after_script = [ "./clean" "finalize_nix_ci" ];
cache = [{
key = "simple";
paths = [ "~/random/" ];
}{
key = "random";
paths = [ ".nix-cache/" ];
}];
variables = {
SAMPLE = "working";
HELLO = toString pkgs.hello;
NIX_CI_CACHE_STRATEGY = "runner";
};
};
};
actual = (mkPipeline {
name = "test";
nixConfig = {
enable = true;
enableRunnerCache = true;
runnerCacheKey = "random";
};
pipeline = {
stages = [ "test" ];
variables = {
EXAMPLE = "empty";
CURL = toString pkgs.curl;
};
jobs.test = {
stage = "test";
before_script = [ "./init" ];
script = [ "echo Hello World!" ];
after_script = [ "./clean" ];
cache = {
key = "simple";
paths = [ "~/random/" ];
};
variables = {
SAMPLE = "working";
HELLO = toString pkgs.hello;
};
};
};
}).finalConfig;