Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ lazy attribute set of function that evaluates to a(n) lazy attribute set of modu



## jobProfiles



Job Profiles to use for common type of jobs\.



*Type:*
lazy attribute set of raw value



*Default:*
` { } `

*Declared by:*
- [job-profiles/interface\.nix](job-profiles/interface.nix)



## jobSets


Expand Down Expand Up @@ -178,6 +199,7 @@ lazy attribute set of (Job configuration)
*Declared by:*
- [jobs/interface\.nix](jobs/interface.nix)
- [job-sets](job-sets)
- [job-profiles](job-profiles)



Expand Down Expand Up @@ -537,6 +559,27 @@ module



## jobs\.\<name>\.profile



Profile to use for the job\.



*Type:*
null or string



*Default:*
` null `

*Declared by:*
- [job-profiles/job-integration\.nix](job-profiles/job-integration.nix)



## jobs\.\<name>\.tags


Expand Down
1 change: 1 addition & 0 deletions module/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
./interface.nix
./jobs
./job-interfaces
./job-profiles
./job-sets
];

Expand Down
13 changes: 13 additions & 0 deletions module/job-profiles/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ lib, ... }:

{
imports = [ ./interface.nix ];

options.jobs = lib.mkOption {
type = lib.types.lazyAttrsOf (
lib.types.submoduleWith {
modules = [ ./job-integration.nix ];
}
);
};
}
12 changes: 12 additions & 0 deletions module/job-profiles/interface.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{ lib, ... }:

let
inherit (lib) types;
in
{
options.jobProfiles = lib.mkOption {
type = types.lazyAttrsOf types.raw;
default = { };
description = "Job Profiles to use for common type of jobs.";
};
}
33 changes: 33 additions & 0 deletions module/job-profiles/job-integration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
lib,
config,
rootConfig,
options,
...
}:

let
inherit (lib) types;
inherit (rootConfig) jobProfiles;
jobProfile = if config.profile != null then jobProfiles.${config.profile} or { } else { };

jobOptionNames = lib.pipe options [
(lib.flip builtins.removeAttrs [
"_module"
"profile"
"tags"
])
builtins.attrNames
];
in
{
options.profile = lib.mkOption {
type = types.nullOr types.str;
default = null;
description = "Profile to use for the job.";
};

config = lib.mkIf (jobProfile != { }) (
lib.genAttrs jobOptionNames (n: lib.mkIf (jobProfile ? ${n}) jobProfile.${n})
);
}
19 changes: 19 additions & 0 deletions module/tests/gitlab-ci/job.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@
};
};

test-gitlab-ci-job-with-profile = {
expr = test-lib.eval-gitlab-ci {
jobProfiles.profile1 = {
image = "profile-image";
};

jobs.job1 = {
profile = "profile1";
commands = [ "echo 'Run your script here'" ];
};
};
expected = {
job1 = {
image = "profile-image";
script = [ "echo 'Run your script here'" ];
};
};
};

test-gitlab-ci-job-transform-name = {
expr = test-lib.eval-gitlab-ci {
pipeline.gitlab-ci.transformJobName = builtins.replaceStrings [ "_" ] [ ":" ];
Expand Down
Loading