fix: pipelines can have either trigger or script

They canno thave both, so here I add assertions support and use them to avoid this case.
This commit is contained in:
Jairo Llopis 2026-05-13 08:53:15 +01:00
parent 097f775cff
commit 70dc878112
No known key found for this signature in database
GPG key ID: B24A1D10508180D8
8 changed files with 107 additions and 19 deletions

View file

@ -1,10 +1,11 @@
{
lib,
cilib,
pkgs,
...
}: let
inherit (lib) mkOption types filterAttrs;
inherit (cilib.helpers) filterUnset mkUnsetOption eitherWithSubOptions;
inherit (cilib.helpers) filterUnset mkUnsetOption eitherWithSubOptions isUnset;
in rec {
jobConfigSubmodule = {pipelineConfig, ...}: {
options = {
@ -511,11 +512,13 @@ in rec {
[Docs](https://docs.gitlab.com/ci/yaml/#rules)
'';
};
script = mkOption {
script = mkUnsetOption {
type = types.listOf types.str;
description = ''
Shell script that is executed by a runner.
A job can have either `script` or `trigger` defined, but not both.
[Docs](https://docs.gitlab.com/ci/yaml/#script)
'';
};
@ -567,6 +570,8 @@ in rec {
description = ''
Defines a downstream pipeline trigger.
A job can have either `script` or `trigger` defined, but not both.
[Docs](https://docs.gitlab.com/ci/yaml/#trigger)
'';
};
@ -589,6 +594,7 @@ in rec {
};
};
in {
imports = [(pkgs.path + /nixos/modules/misc/assertions.nix)];
options =
{
nix = mkOption {
@ -636,9 +642,19 @@ in rec {
}
// gitlabOptions;
config = let
attrsToKeep = builtins.attrNames gitlabOptions;
job = filterUnset (filterAttrs (n: _v: builtins.elem n attrsToKeep) config);
jobHasScript = builtins.hasAttr "script" job;
jobHasTrigger = builtins.hasAttr "trigger" job;
in {
assertions = [
{
assertion = !(jobHasScript && jobHasTrigger);
message = "Job '${name}' in pipeline '${pipelineName}' cannot have both 'script' and 'trigger' defined.";
}
];
finalConfig = cilib.mkJobPatched {
key = name;
nixConfig = config.nix;