mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2026-06-19 08:39:26 +02:00
feat: auto-generate CI jobs from flake checks
Add `checks` option and `config.autoChecks` to auto-generate a CI job for each flake check derivation. Auto-generated jobs go through `mkJobPatched` for proper Nix setup, cache, and environment handling. The `checks` option is automatically wired to `config.checks` in flake-parts. System is inferred from `pkgs.system` and set via the new `system` option. User-defined jobs with the same name always take precedence. New tests cover both flake-parts and direct API entry points. MT-14138
This commit is contained in:
parent
097f775cff
commit
ab41bc24ec
8 changed files with 388 additions and 5 deletions
65
tests/auto_checks_test.nix
Normal file
65
tests/auto_checks_test.nix
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
{
|
||||
pkgs,
|
||||
ntlib,
|
||||
cilib,
|
||||
...
|
||||
}: {
|
||||
suites."autoChecks" = {
|
||||
pos = __curPos;
|
||||
tests = [
|
||||
{
|
||||
name = "flakeModule";
|
||||
type = "script";
|
||||
script =
|
||||
# sh
|
||||
''
|
||||
${ntlib.helpers.scriptHelpers}
|
||||
${ntlib.helpers.path (with pkgs; [coreutils nix gnused gnugrep jq])}
|
||||
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
|
||||
export NIX_SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
|
||||
repo_path=${../.}
|
||||
|
||||
cp ${./fixtures/flake_parts_autochecks}/* .
|
||||
sed -i -e "s|@repo_path@|$repo_path|" flake.nix
|
||||
|
||||
nix build --impure .#gitlab-ci:pipeline:default
|
||||
assert "-f result" "should exist"
|
||||
|
||||
system=$(nix eval --impure --expr "builtins.currentSystem" --raw)
|
||||
jq -e '."my-check" | .stage == "test"' result > /dev/null
|
||||
jq -e '."my-check" | .script[0] | contains("nix build")' result > /dev/null
|
||||
jq -e '."my-check" | .script[0] | contains("'"$system"'")' result > /dev/null
|
||||
jq -e '."my-check" | has("before_script")' result > /dev/null
|
||||
jq -e '."my-check" | has("after_script")' result > /dev/null
|
||||
'';
|
||||
}
|
||||
{
|
||||
name = "direct";
|
||||
type = "script";
|
||||
script = let
|
||||
system = pkgs.system;
|
||||
fakeCheck = pkgs.runCommand "fake-check" {} "touch $out";
|
||||
ci = cilib.mkCI {
|
||||
checks.my-check = fakeCheck;
|
||||
config.autoChecks.enable = true;
|
||||
pipelines.default.stages = [ "test" ];
|
||||
};
|
||||
pkg = ci.packages."gitlab-ci:pipeline:default";
|
||||
in
|
||||
# sh
|
||||
''
|
||||
${ntlib.helpers.scriptHelpers}
|
||||
${ntlib.helpers.path (with pkgs; [coreutils gnugrep jq])}
|
||||
|
||||
json=$(cat ${pkg})
|
||||
echo "$json" | jq -e '.stages == [".pre", "test", ".post"]' > /dev/null
|
||||
echo "$json" | jq -e '."my-check" | .stage == "test"' > /dev/null
|
||||
echo "$json" | jq -e '."my-check" | .script[0] | contains("nix build")' > /dev/null
|
||||
echo "$json" | jq -e '."my-check" | .script[0] | contains("${system}")' > /dev/null
|
||||
echo "$json" | jq -e '."my-check" | has("before_script")' > /dev/null
|
||||
echo "$json" | jq -e '."my-check" | has("after_script")' > /dev/null
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue