mirror of
https://gitlab.com/TECHNOFAB/nix-gitlab-ci.git
synced 2026-06-19 08:39:26 +02:00
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:
parent
097f775cff
commit
70dc878112
8 changed files with 107 additions and 19 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue