mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2025-12-11 17:50:08 +01:00
Compare commits
16 commits
bdbc12771f
...
8a752f92cf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a752f92cf | ||
|
|
65b90ecd65 | ||
|
|
c8f51c73ed | ||
|
|
8336e6d083 | ||
|
|
0ef6f4d2ff | ||
|
|
fb234b80bf | ||
|
|
d8e55a05b2 | ||
| 59f8bd169a | |||
| 97fb4fafc3 | |||
| 1c9e7c77c5 | |||
|
|
fc79dd5120 | ||
|
|
8487c78246 | ||
|
|
0f9d0aae60 | ||
|
|
d2f8a70675 | ||
|
|
f84edb7760 | ||
|
|
58a0db7861 |
7 changed files with 106 additions and 24 deletions
|
|
@ -9,3 +9,14 @@ This project provides a Nix flake module that allows you to generate your `.gitl
|
||||||
- **Modularity:** Define and manage your CI configurations in a structured and modular way using Nix modules, making it easier to share and reuse CI logic across multiple projects.
|
- **Modularity:** Define and manage your CI configurations in a structured and modular way using Nix modules, making it easier to share and reuse CI logic across multiple projects.
|
||||||
|
|
||||||
This documentation will guide you through setting up and using Nix GitLab CI for your projects.
|
This documentation will guide you through setting up and using Nix GitLab CI for your projects.
|
||||||
|
|
||||||
|
## Warnings
|
||||||
|
|
||||||
|
To save you from frantically searching these docs if something doesn't work as expected, here are the most important warnings ;)
|
||||||
|
|
||||||
|
!!! warning
|
||||||
|
|
||||||
|
Do not put Nix store paths into global/pipeline variables. They will simply be passed through,
|
||||||
|
resulting in bad portability (if two runners have different archs for example, one cannot find the path).
|
||||||
|
If you need any Nix store path in env variables, always do it on the job level, there
|
||||||
|
it will automatically be computed at runtime, thus will always work no matter which runner it runs on.
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
3.0.1
|
3.1.0
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,13 @@ in
|
||||||
pipelineName,
|
pipelineName,
|
||||||
nixConfig,
|
nixConfig,
|
||||||
}:
|
}:
|
||||||
(builtins.removeAttrs job ["variables" "cache"])
|
if ! nixConfig.enable
|
||||||
// (optionalAttrs nixConfig.enable (
|
then job
|
||||||
(prependToBeforeScript ["source setup_nix_ci \"gitlab-ci:pipeline:${pipelineName}:job-deps:${key}\""] 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)
|
// (appendToAfterScript ["finalize_nix_ci"] job)
|
||||||
))
|
// (let
|
||||||
// optionalAttrs nixConfig.enable (
|
|
||||||
(let
|
|
||||||
variables =
|
variables =
|
||||||
(filterJobVariables false job)
|
(filterJobVariables false job)
|
||||||
// optionalAttrs nixConfig.enableRunnerCache {
|
// optionalAttrs nixConfig.enableRunnerCache {
|
||||||
|
|
@ -40,4 +40,3 @@ in
|
||||||
optionalAttrs (cache != []) {
|
optionalAttrs (cache != []) {
|
||||||
inherit cache;
|
inherit cache;
|
||||||
})
|
})
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -646,7 +646,7 @@ in rec {
|
||||||
};
|
};
|
||||||
depsDrv = cilib.mkJobDeps {
|
depsDrv = cilib.mkJobDeps {
|
||||||
key = name;
|
key = name;
|
||||||
job = config.finalConfig;
|
inherit job;
|
||||||
nixConfig = config.nix;
|
nixConfig = config.nix;
|
||||||
};
|
};
|
||||||
runnerDrv = cilib.mkJobRun {
|
runnerDrv = cilib.mkJobRun {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{inputs, ...}: let
|
{inputs, ...}: let
|
||||||
inherit (inputs) cilib;
|
inherit (inputs) cilib pkgs;
|
||||||
in
|
in
|
||||||
cilib.mkCI {
|
cilib.mkCI {
|
||||||
config.soonix = {
|
config.soonix = {
|
||||||
|
|
@ -58,9 +58,25 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
pipelines."default" = {
|
pipelines."default" = {
|
||||||
stages = ["test" "build" "deploy"];
|
stages = ["check" "test" "build" "deploy"];
|
||||||
|
variables = {
|
||||||
|
EXAMPLE = "empty";
|
||||||
|
CURL = toString pkgs.curl;
|
||||||
|
};
|
||||||
jobs = {
|
jobs = {
|
||||||
|
"check" = {
|
||||||
|
stage = "check";
|
||||||
|
script = [
|
||||||
|
"set -euo pipefail"
|
||||||
|
"echo EXAMPLE=$EXAMPLE CURL=$CURL SAMPLE=$SAMPLE HELLO=$HELLO"
|
||||||
|
];
|
||||||
|
variables = {
|
||||||
|
SAMPLE = "working";
|
||||||
|
HELLO = toString pkgs.hello;
|
||||||
|
};
|
||||||
|
};
|
||||||
"test" = {
|
"test" = {
|
||||||
|
nix.deps = with pkgs; [coreutils nix];
|
||||||
stage = "test";
|
stage = "test";
|
||||||
script = [
|
script = [
|
||||||
"nix run .#tests -- --junit=junit.xml"
|
"nix run .#tests -- --junit=junit.xml"
|
||||||
|
|
@ -73,6 +89,7 @@ in
|
||||||
};
|
};
|
||||||
"docs" = {
|
"docs" = {
|
||||||
stage = "build";
|
stage = "build";
|
||||||
|
nix.deps = with pkgs; [coreutils nix];
|
||||||
script = [
|
script = [
|
||||||
# sh
|
# sh
|
||||||
''
|
''
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,22 @@
|
||||||
nixConfig.enable = false;
|
nixConfig.enable = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
name = "jobPatched nix disabled with variables and cache";
|
||||||
|
expected = {
|
||||||
|
variables."HELLO" = "world";
|
||||||
|
cache = [{key = "example";}];
|
||||||
|
};
|
||||||
|
actual = mkJobPatched {
|
||||||
|
key = "test";
|
||||||
|
pipelineName = "test";
|
||||||
|
job = {
|
||||||
|
variables."HELLO" = "world";
|
||||||
|
cache = [{key = "example";}];
|
||||||
|
};
|
||||||
|
nixConfig.enable = false;
|
||||||
|
};
|
||||||
|
}
|
||||||
{
|
{
|
||||||
name = "jobPatched without runner cache";
|
name = "jobPatched without runner cache";
|
||||||
expected = {
|
expected = {
|
||||||
|
|
@ -145,10 +161,13 @@
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "handle store paths in variables";
|
name = "ignore store paths in variables with nix disabled";
|
||||||
expected = {
|
expected = {
|
||||||
stages = ["test"];
|
stages = ["test"];
|
||||||
test.stage = "test";
|
test = {
|
||||||
|
stage = "test";
|
||||||
|
variables."TEST" = "${pkgs.hello}";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
actual =
|
actual =
|
||||||
(mkPipeline {
|
(mkPipeline {
|
||||||
|
|
@ -163,6 +182,28 @@
|
||||||
};
|
};
|
||||||
}).finalConfig;
|
}).finalConfig;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
# it doesn't make much sense to have any nix store path in variables, but we ignore it for global variables
|
||||||
|
name = "ignore store paths in global variables";
|
||||||
|
expected = {
|
||||||
|
variables = {
|
||||||
|
HELLO = "world";
|
||||||
|
CURL = toString pkgs.curl;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
actual =
|
||||||
|
(mkPipeline {
|
||||||
|
name = "test";
|
||||||
|
nixConfig.enable = true;
|
||||||
|
pipeline = {
|
||||||
|
variables = {
|
||||||
|
HELLO = "world";
|
||||||
|
CURL = toString pkgs.curl;
|
||||||
|
};
|
||||||
|
jobs = {};
|
||||||
|
};
|
||||||
|
}).finalConfig;
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,17 @@
|
||||||
simplePipeline = cilib.mkCI {
|
simplePipeline = cilib.mkCI {
|
||||||
pipelines."test" = {
|
pipelines."test" = {
|
||||||
stages = ["test"];
|
stages = ["test"];
|
||||||
|
variables = {
|
||||||
|
EXAMPLE = "empty";
|
||||||
|
CURL = toString pkgs.curl;
|
||||||
|
};
|
||||||
jobs."test" = {
|
jobs."test" = {
|
||||||
stage = "test";
|
stage = "test";
|
||||||
script = ["echo hello world"];
|
script = ["echo hello world"];
|
||||||
|
variables = {
|
||||||
|
SAMPLE = "working";
|
||||||
|
HELLO = toString pkgs.hello;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
@ -30,21 +38,29 @@
|
||||||
(cilib.mkCI {}).packages;
|
(cilib.mkCI {}).packages;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "simple pipeline";
|
name = "simple pipeline final config";
|
||||||
expected = {
|
expected = {
|
||||||
stages = [".pre" "test" ".post"];
|
stages = [".pre" "test" ".post"];
|
||||||
|
variables = {
|
||||||
|
EXAMPLE = "empty";
|
||||||
|
CURL = toString pkgs.curl;
|
||||||
|
};
|
||||||
"test" = {
|
"test" = {
|
||||||
image = "$NIX_CI_IMAGE";
|
image = "$NIX_CI_IMAGE";
|
||||||
stage = "test";
|
stage = "test";
|
||||||
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\""];
|
||||||
script = ["echo hello world"];
|
script = ["echo hello world"];
|
||||||
after_script = ["finalize_nix_ci"];
|
after_script = ["finalize_nix_ci"];
|
||||||
|
variables = {
|
||||||
|
SAMPLE = "working";
|
||||||
|
#HELLO = toString pkgs.hello;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
actual = simplePipeline.pipelines."test".finalConfig;
|
actual = simplePipeline.pipelines."test".finalConfig;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "simple pipeline yaml";
|
name = "simple pipeline json";
|
||||||
type = "script";
|
type = "script";
|
||||||
script = let
|
script = let
|
||||||
package = simplePipeline.packages."gitlab-ci:pipeline:test";
|
package = simplePipeline.packages."gitlab-ci:pipeline:test";
|
||||||
|
|
@ -56,25 +72,23 @@
|
||||||
assert_file_contains ${package} 'gitlab-ci:pipeline:test:job-deps:test'
|
assert_file_contains ${package} 'gitlab-ci:pipeline:test:job-deps:test'
|
||||||
assert_file_contains ${package} 'finalize_nix_ci'
|
assert_file_contains ${package} 'finalize_nix_ci'
|
||||||
assert_file_contains ${package} 'echo hello world'
|
assert_file_contains ${package} 'echo hello world'
|
||||||
|
assert_file_contains ${package} '"EXAMPLE":"empty"'
|
||||||
|
assert_file_contains ${package} '"SAMPLE":"working"'
|
||||||
|
assert_file_contains ${package} '"CURL":"/nix/store/.*-curl-.*"'
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name = "dont fail on store paths";
|
name = "simple pipeline deps drv";
|
||||||
type = "script";
|
type = "script";
|
||||||
script = let
|
script = let
|
||||||
package =
|
package = simplePipeline.packages."gitlab-ci:pipeline:test:job-deps:test";
|
||||||
(cilib.mkCI {
|
|
||||||
pipelines."test" = {
|
|
||||||
variables.EXAMPLE = "${pkgs.hello}";
|
|
||||||
};
|
|
||||||
}).packages."gitlab-ci:pipeline:test";
|
|
||||||
in
|
in
|
||||||
# sh
|
# sh
|
||||||
''
|
''
|
||||||
${ntlib.helpers.path [pkgs.gnugrep]}
|
${ntlib.helpers.path [pkgs.gnugrep]}
|
||||||
${ntlib.helpers.scriptHelpers}
|
${ntlib.helpers.scriptHelpers}
|
||||||
assert_file_contains ${package} '[".pre",".post"]'
|
assert_file_contains ${package} ':$PATH'
|
||||||
assert_file_contains ${package} '"EXAMPLE":"/nix/store/.*-hello-.*"'
|
assert_file_contains ${package} 'HELLO="/nix/store/.*-hello-.*"'
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue