Skip to content
Merged
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
63 changes: 63 additions & 0 deletions module/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,27 @@ YAML value



## jobs\.\<name>\.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\.\<name>\.gitlab-ci


Expand All @@ -390,6 +411,27 @@ YAML value



## jobs\.\<name>\.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\.\<name>\.image


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



## jobs\.\<name>\.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\.\<name>\.tags


Expand Down
11 changes: 7 additions & 4 deletions module/jobs/default.nix
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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"
);
};
};
}
4 changes: 2 additions & 2 deletions module/jobs/github-actions/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 [ ]))
Expand Down Expand Up @@ -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)
];
}
2 changes: 1 addition & 1 deletion module/jobs/job/github-actions.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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)
];
Expand Down
2 changes: 1 addition & 1 deletion module/jobs/job/gitlab-ci.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 43 additions & 3 deletions module/jobs/job/interface.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
lib,
name,
rootConfig,
config,
...
}:

Expand Down Expand Up @@ -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.";
};
Expand Down
2 changes: 1 addition & 1 deletion module/jobs/job/process-compose.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
64 changes: 64 additions & 0 deletions module/tests/github-actions/job.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"; }
];
};
};
};
};
}
51 changes: 51 additions & 0 deletions module/tests/gitlab-ci/job.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];
};
};
};
}