diff --git a/module/README.md b/module/README.md index c916902..9360f0d 100644 --- a/module/README.md +++ b/module/README.md @@ -369,6 +369,27 @@ YAML value +## jobs\.\\.github-actions\.enable + + + +Whether the job is enabled for GitHub Actions\. + + + +*Type:* +boolean + + + +*Default:* +` true ` + +*Declared by:* + - [jobs/job/interface\.nix](jobs/job/interface.nix) + + + ## jobs\.\\.gitlab-ci @@ -390,6 +411,27 @@ YAML value +## jobs\.\\.gitlab-ci\.enable + + + +Whether the job is enabled for GitLab CI\. + + + +*Type:* +boolean + + + +*Default:* +` true ` + +*Declared by:* + - [jobs/job/interface\.nix](jobs/job/interface.nix) + + + ## jobs\.\\.image @@ -537,6 +579,27 @@ module +## jobs\.\\.process-compose\.enable + + + +Whether the job is enabled for process-compose\. + + + +*Type:* +boolean + + + +*Default:* +` true ` + +*Declared by:* + - [jobs/job/interface\.nix](jobs/job/interface.nix) + + + ## jobs\.\\.tags diff --git a/module/jobs/default.nix b/module/jobs/default.nix index 382fd07..67a2a23 100644 --- a/module/jobs/default.nix +++ b/module/jobs/default.nix @@ -1,7 +1,8 @@ { lib, config, ... }: let - enabledJobs = lib.filterAttrs (_: builtins.getAttr "enable") config.jobs; + enabledForBackend = + backend: lib.filterAttrs (_: job: job.enable && job.${backend}.enable) config.jobs; in { imports = [ @@ -12,11 +13,13 @@ in config.pipeline = { gitlab-ci.settings = lib.mapAttrs' (name: job: { name = config.pipeline.gitlab-ci.transformJobName name; - value = job.gitlab-ci; - }) enabledJobs; + value = builtins.removeAttrs job.gitlab-ci [ "enable" ]; + }) (enabledForBackend "gitlab-ci"); process-compose.settings = { - processes = lib.mapAttrs (_: job: job.process-compose) enabledJobs; + processes = lib.mapAttrs (_: job: builtins.removeAttrs job.process-compose [ "enable" ]) ( + enabledForBackend "process-compose" + ); }; }; } diff --git a/module/jobs/github-actions/default.nix b/module/jobs/github-actions/default.nix index e947f03..56acab4 100644 --- a/module/jobs/github-actions/default.nix +++ b/module/jobs/github-actions/default.nix @@ -2,7 +2,7 @@ let inherit (config.pipeline.github-actions) checkoutAction; - enabledJobs = lib.filterAttrs (_: builtins.getAttr "enable") config.jobs; + enabledJobs = lib.filterAttrs (_: job: job.enable && job.github-actions.enable) config.jobs; changes = lib.pipe enabledJobs [ (builtins.mapAttrs (_: job: job.branches.default.changes.paths or [ ])) @@ -31,7 +31,7 @@ in (lib.mapAttrs' (name: job: { name = config.pipeline.github-actions.transformJobName name; - value = job.github-actions; + value = builtins.removeAttrs job.github-actions [ "enable" ]; }) enabledJobs) ]; } diff --git a/module/jobs/job/github-actions.nix b/module/jobs/job/github-actions.nix index 39c4bc8..5c884bc 100644 --- a/module/jobs/job/github-actions.nix +++ b/module/jobs/job/github-actions.nix @@ -11,7 +11,7 @@ let inherit (rootConfig.pipeline.github-actions) defaultRunsOn transformJobName checkoutAction; needs = lib.pipe config.needs [ - (builtins.filter (need: jobs.${need.job}.enable)) + (builtins.filter (need: jobs.${need.job}.enable && jobs.${need.job}.github-actions.enable)) (builtins.catAttrs "job") (map transformJobName) ]; diff --git a/module/jobs/job/gitlab-ci.nix b/module/jobs/job/gitlab-ci.nix index 312793c..5e704a4 100644 --- a/module/jobs/job/gitlab-ci.nix +++ b/module/jobs/job/gitlab-ci.nix @@ -10,7 +10,7 @@ let inherit (rootConfig.pipeline.gitlab-ci) defaultStage transformJobName; needs = lib.pipe config.needs [ - (builtins.filter (need: jobs.${need.job}.enable)) + (builtins.filter (need: jobs.${need.job}.enable && jobs.${need.job}.gitlab-ci.enable)) (map (need: need // { job = transformJobName need.job; })) ]; triggersBranchConfig = map (job: jobs.${job}.branches) config.triggers; diff --git a/module/jobs/job/interface.nix b/module/jobs/job/interface.nix index 462eb41..7c60da3 100644 --- a/module/jobs/job/interface.nix +++ b/module/jobs/job/interface.nix @@ -2,6 +2,7 @@ lib, name, rootConfig, + config, ... }: @@ -131,19 +132,58 @@ in }; github-actions = lib.mkOption { - type = rootConfig.types.yamlType; + type = types.submoduleWith { + modules = [ + { + options = { + enable = lib.mkOption { + type = types.bool; + default = true; + description = "Whether the job is enabled for GitHub Actions."; + }; + }; + config._module.freeformType = rootConfig.types.yamlType; + } + ]; + }; default = { }; description = "Job configuration targeting GitHub Actions."; }; gitlab-ci = lib.mkOption { - type = rootConfig.types.yamlType; + type = types.submoduleWith { + modules = [ + { + options = { + enable = lib.mkOption { + type = types.bool; + default = true; + description = "Whether the job is enabled for GitLab CI."; + }; + }; + config._module.freeformType = rootConfig.types.yamlType; + } + ]; + }; default = { }; description = "Job configuration targeting GitLab CI."; }; process-compose = lib.mkOption { - type = types.deferredModule; + type = types.submoduleWith { + modules = [ + { + options = { + enable = lib.mkOption { + type = types.bool; + default = true; + description = "Whether the job is enabled for process-compose."; + }; + }; + config._module.freeformType = types.deferredModule; + } + ]; + }; default = { }; description = "Job configuration targeting process-compose."; }; diff --git a/module/jobs/job/process-compose.nix b/module/jobs/job/process-compose.nix index b17c24b..566f275 100644 --- a/module/jobs/job/process-compose.nix +++ b/module/jobs/job/process-compose.nix @@ -9,7 +9,7 @@ let inherit (rootConfig) jobs; depends_on = lib.pipe config.needs [ - (builtins.filter (need: jobs.${need.job}.enable)) + (builtins.filter (need: jobs.${need.job}.enable && jobs.${need.job}.process-compose.enable)) (builtins.catAttrs "job") (lib.flip lib.genAttrs (_: { condition = "process_completed_successfully"; diff --git a/module/tests/github-actions/job.nix b/module/tests/github-actions/job.nix index 6340f84..fd9bcc4 100644 --- a/module/tests/github-actions/job.nix +++ b/module/tests/github-actions/job.nix @@ -230,4 +230,68 @@ }; }; }; + + test-github-actions-job-per-backend-disable = { + expr = test-lib.eval-github-actions { + pipeline.github-actions.defaultRunsOn = "ubuntu-latest"; + jobs = { + job-a = { + commands = [ "echo job-a" ]; + }; + job-b = { + commands = [ "echo job-b" ]; + github-actions.enable = false; + }; + job-c = { + commands = [ "echo job-c" ]; + needs = [ { job = "job-b"; } ]; + }; + }; + }; + expected = { + jobs = { + job-a = { + runs-on = "ubuntu-latest"; + steps = [ + { uses = "actions/checkout@v6"; } + { run = "echo job-a"; } + ]; + }; + job-c = { + runs-on = "ubuntu-latest"; + steps = [ + { uses = "actions/checkout@v6"; } + { run = "echo job-c"; } + ]; + }; + }; + }; + }; + + test-github-actions-job-global-disable-overrides-per-backend-enable = { + expr = test-lib.eval-github-actions { + pipeline.github-actions.defaultRunsOn = "ubuntu-latest"; + jobs = { + job-a = { + commands = [ "echo job-a" ]; + }; + job-b = { + commands = [ "echo job-b" ]; + enable = false; + github-actions.enable = true; + }; + }; + }; + expected = { + jobs = { + job-a = { + runs-on = "ubuntu-latest"; + steps = [ + { uses = "actions/checkout@v6"; } + { run = "echo job-a"; } + ]; + }; + }; + }; + }; } diff --git a/module/tests/gitlab-ci/job.nix b/module/tests/gitlab-ci/job.nix index 05dcd68..79917d8 100644 --- a/module/tests/gitlab-ci/job.nix +++ b/module/tests/gitlab-ci/job.nix @@ -281,4 +281,55 @@ job.environment = "test"; }; }; + + test-gitlab-ci-job-per-backend-disable = { + expr = test-lib.eval-gitlab-ci { + pipeline.gitlab-ci.defaultStage = "test"; + jobs = { + job-a = { + commands = [ "echo job-a" ]; + }; + job-b = { + commands = [ "echo job-b" ]; + gitlab-ci.enable = false; + }; + job-c = { + commands = [ "echo job-c" ]; + needs = [ { job = "job-b"; } ]; + }; + }; + }; + expected = { + job-a = { + stage = "test"; + script = [ "echo job-a" ]; + }; + job-c = { + stage = "test"; + script = [ "echo job-c" ]; + }; + }; + }; + + test-gitlab-ci-job-global-disable-overrides-per-backend-enable = { + expr = test-lib.eval-gitlab-ci { + pipeline.gitlab-ci.defaultStage = "test"; + jobs = { + job-a = { + commands = [ "echo job-a" ]; + }; + job-b = { + commands = [ "echo job-b" ]; + enable = false; + gitlab-ci.enable = true; + }; + }; + }; + expected = { + job-a = { + stage = "test"; + script = [ "echo job-a" ]; + }; + }; + }; }