diff --git a/module/README.md b/module/README.md index 6292b37..6fce9bb 100644 --- a/module/README.md +++ b/module/README.md @@ -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 @@ -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) @@ -537,6 +559,27 @@ module +## jobs\.\\.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\.\\.tags diff --git a/module/default.nix b/module/default.nix index 8e1320d..5c25ead 100644 --- a/module/default.nix +++ b/module/default.nix @@ -5,6 +5,7 @@ ./interface.nix ./jobs ./job-interfaces + ./job-profiles ./job-sets ]; diff --git a/module/job-profiles/default.nix b/module/job-profiles/default.nix new file mode 100644 index 0000000..4932563 --- /dev/null +++ b/module/job-profiles/default.nix @@ -0,0 +1,13 @@ +{ lib, ... }: + +{ + imports = [ ./interface.nix ]; + + options.jobs = lib.mkOption { + type = lib.types.lazyAttrsOf ( + lib.types.submoduleWith { + modules = [ ./job-integration.nix ]; + } + ); + }; +} diff --git a/module/job-profiles/interface.nix b/module/job-profiles/interface.nix new file mode 100644 index 0000000..1b70c07 --- /dev/null +++ b/module/job-profiles/interface.nix @@ -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."; + }; +} diff --git a/module/job-profiles/job-integration.nix b/module/job-profiles/job-integration.nix new file mode 100644 index 0000000..72c05ab --- /dev/null +++ b/module/job-profiles/job-integration.nix @@ -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}) + ); +} diff --git a/module/tests/gitlab-ci/job.nix b/module/tests/gitlab-ci/job.nix index 05dcd68..4ac0642 100644 --- a/module/tests/gitlab-ci/job.nix +++ b/module/tests/gitlab-ci/job.nix @@ -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 [ "_" ] [ ":" ];