mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2025-12-12 10:10:06 +01:00
Compare commits
7 commits
8a752f92cf
...
bdbc12771f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdbc12771f | ||
|
|
fc79dd5120 | ||
|
|
8487c78246 | ||
|
|
0f9d0aae60 | ||
|
|
d2f8a70675 | ||
|
|
f84edb7760 | ||
|
|
58a0db7861 |
2 changed files with 190 additions and 59 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
helpers,
|
helpers,
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) toList optionalAttrs optional;
|
inherit (lib) toList optionalAttrs optional;
|
||||||
inherit (helpers) prependToBeforeScript appendToAfterScript filterJobVariables;
|
inherit (helpers) prependToBeforeScript appendToAfterScript;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
key,
|
key,
|
||||||
|
|
@ -11,33 +11,28 @@ in
|
||||||
pipelineName,
|
pipelineName,
|
||||||
nixConfig,
|
nixConfig,
|
||||||
}:
|
}:
|
||||||
(builtins.removeAttrs job ["variables" "cache"])
|
if ! nixConfig.enable then job else
|
||||||
// (optionalAttrs nixConfig.enable (
|
(builtins.removeAttrs job [ "variables" "cache" ])
|
||||||
(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 (
|
variables = job.variables or {} //
|
||||||
(let
|
optionalAttrs nixConfig.enableRunnerCache {
|
||||||
variables =
|
NIX_CI_CACHE_STRATEGY = "runner";
|
||||||
(filterJobVariables false job)
|
};
|
||||||
// optionalAttrs nixConfig.enableRunnerCache {
|
in
|
||||||
NIX_CI_CACHE_STRATEGY = "runner";
|
# filter empty variables
|
||||||
};
|
optionalAttrs (variables != {}) {
|
||||||
in
|
inherit variables;
|
||||||
# filter empty variables
|
})
|
||||||
optionalAttrs (variables != {}) {
|
// (let
|
||||||
inherit variables;
|
cache = (toList (job.cache or [])) ++
|
||||||
})
|
(optional nixConfig.enableRunnerCache {
|
||||||
// (let
|
key = nixConfig.runnerCacheKey;
|
||||||
cache =
|
paths = [ ".nix-cache/" ];
|
||||||
(toList (job.cache or []))
|
});
|
||||||
++ (optional nixConfig.enableRunnerCache {
|
in
|
||||||
key = nixConfig.runnerCacheKey;
|
# filter empty cache
|
||||||
paths = [".nix-cache/"];
|
optionalAttrs (cache != []) {
|
||||||
});
|
inherit cache;
|
||||||
in
|
})
|
||||||
# filter empty cache
|
|
||||||
optionalAttrs (cache != []) {
|
|
||||||
inherit cache;
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -56,24 +56,59 @@
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "jobPatched nix disabled";
|
name = "jobPatched nix disabled";
|
||||||
expected = {};
|
expected = {
|
||||||
|
cache = {
|
||||||
|
name = "some";
|
||||||
|
paths = [ "this" ];
|
||||||
|
};
|
||||||
|
variables = {
|
||||||
|
BASH = toString pkgs.bash;
|
||||||
|
TEST = "work";
|
||||||
|
};
|
||||||
|
};
|
||||||
actual = mkJobPatched {
|
actual = mkJobPatched {
|
||||||
key = "test";
|
key = "test";
|
||||||
pipelineName = "test";
|
pipelineName = "test";
|
||||||
job = {};
|
job = {
|
||||||
|
cache = {
|
||||||
|
name = "some";
|
||||||
|
paths = [ "this" ];
|
||||||
|
};
|
||||||
|
variables = {
|
||||||
|
BASH = toString pkgs.bash;
|
||||||
|
TEST = "work";
|
||||||
|
};
|
||||||
|
};
|
||||||
nixConfig.enable = false;
|
nixConfig.enable = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "jobPatched without runner cache";
|
name = "jobPatched without runner cache";
|
||||||
expected = {
|
expected = {
|
||||||
after_script = ["finalize_nix_ci"];
|
after_script = [ "finalize_nix_ci" ];
|
||||||
before_script = ["source setup_nix_ci \"gitlab-ci:pipeline:test:job-deps:test\""];
|
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 {
|
actual = mkJobPatched {
|
||||||
key = "test";
|
key = "test";
|
||||||
pipelineName = "test";
|
pipelineName = "test";
|
||||||
job = {};
|
job = {
|
||||||
|
cache = {
|
||||||
|
name = "some";
|
||||||
|
paths = [ "this" ];
|
||||||
|
};
|
||||||
|
variables = {
|
||||||
|
BASH = toString pkgs.bash;
|
||||||
|
TEST = "work";
|
||||||
|
};
|
||||||
|
};
|
||||||
nixConfig = {
|
nixConfig = {
|
||||||
enable = true;
|
enable = true;
|
||||||
enableRunnerCache = false;
|
enableRunnerCache = false;
|
||||||
|
|
@ -83,20 +118,34 @@
|
||||||
{
|
{
|
||||||
name = "jobPatched with runner cache";
|
name = "jobPatched with runner cache";
|
||||||
expected = {
|
expected = {
|
||||||
after_script = ["finalize_nix_ci"];
|
after_script = [ "finalize_nix_ci" ];
|
||||||
before_script = ["source setup_nix_ci \"gitlab-ci:pipeline:test:job-deps:test\""];
|
before_script = [ "source setup_nix_ci \"gitlab-ci:pipeline:test:job-deps:test\"" ];
|
||||||
cache = [
|
cache = [{
|
||||||
{
|
name = "some";
|
||||||
key = "test";
|
paths = [ "this" ];
|
||||||
paths = [".nix-cache/"];
|
}{
|
||||||
}
|
key = "test";
|
||||||
];
|
paths = [ ".nix-cache/" ];
|
||||||
variables."NIX_CI_CACHE_STRATEGY" = "runner";
|
}];
|
||||||
|
variables = {
|
||||||
|
NIX_CI_CACHE_STRATEGY = "runner";
|
||||||
|
BASH = toString pkgs.bash;
|
||||||
|
TEST = "work";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
actual = mkJobPatched {
|
actual = mkJobPatched {
|
||||||
key = "test";
|
key = "test";
|
||||||
pipelineName = "test";
|
pipelineName = "test";
|
||||||
job = {};
|
job = {
|
||||||
|
cache = {
|
||||||
|
name = "some";
|
||||||
|
paths = [ "this" ];
|
||||||
|
};
|
||||||
|
variables = {
|
||||||
|
BASH = toString pkgs.bash;
|
||||||
|
TEST = "work";
|
||||||
|
};
|
||||||
|
};
|
||||||
nixConfig = {
|
nixConfig = {
|
||||||
enable = true;
|
enable = true;
|
||||||
enableRunnerCache = true;
|
enableRunnerCache = true;
|
||||||
|
|
@ -145,23 +194,110 @@
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "handle store paths in variables";
|
name = "handle store paths in variables without nix config";
|
||||||
expected = {
|
expected = {
|
||||||
stages = ["test"];
|
stages = [ "test" ];
|
||||||
test.stage = "test";
|
variables = {
|
||||||
|
EXAMPLE = "empty";
|
||||||
|
CURL = toString pkgs.curl;
|
||||||
|
};
|
||||||
|
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 =
|
actual = (mkPipeline {
|
||||||
(mkPipeline {
|
name = "test";
|
||||||
name = "test";
|
nixConfig.enable = false;
|
||||||
nixConfig.enable = false;
|
pipeline = {
|
||||||
pipeline = {
|
stages = [ "test" ];
|
||||||
stages = ["test"];
|
variables = {
|
||||||
jobs.test = {
|
EXAMPLE = "empty";
|
||||||
stage = "test";
|
CURL = toString pkgs.curl;
|
||||||
variables."TEST" = "${pkgs.hello}";
|
};
|
||||||
|
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;
|
};
|
||||||
|
}).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;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue