diff --git a/module/jobs/github-actions/default.nix b/module/jobs/github-actions/default.nix index 1edf134..7cadf91 100644 --- a/module/jobs/github-actions/default.nix +++ b/module/jobs/github-actions/default.nix @@ -3,16 +3,9 @@ let enabledJobs = lib.filterAttrs (_: builtins.getAttr "enable") config.jobs; - changesPathsAttrPath = [ - "branches" - "default" - "changes" - "paths" - ]; - changes = lib.pipe enabledJobs [ - (lib.filterAttrs (_: lib.hasAttrByPath changesPathsAttrPath)) - (builtins.mapAttrs (_: lib.getAttrFromPath changesPathsAttrPath)) + (builtins.mapAttrs (_: job: job.branches.default.changes.paths or [ ])) + (lib.filterAttrs (_: paths: paths != [ ])) (builtins.mapAttrs (_: builtins.concatStringsSep "\\|")) (lib.mapAttrsToList (name: paths: "${name}:${paths}")) ]; diff --git a/module/jobs/job/github-actions.nix b/module/jobs/job/github-actions.nix index 4d54526..f47d023 100644 --- a/module/jobs/job/github-actions.nix +++ b/module/jobs/job/github-actions.nix @@ -29,7 +29,7 @@ in ]; } - (lib.mkIf (config ? branches.default.changes.paths) { + (lib.mkIf ((config.branches.default.changes.paths or [ ]) != [ ]) { needs = [ "changes" ]; "if" = "\${{ fromJSON(needs.changes.outputs.changes)['${name}'] == true }}"; }) diff --git a/module/tests/github-actions/job.nix b/module/tests/github-actions/job.nix index 82dca0e..c5899a1 100644 --- a/module/tests/github-actions/job.nix +++ b/module/tests/github-actions/job.nix @@ -118,13 +118,20 @@ expr = test-lib.eval-github-actions { pipeline.github-actions.defaultRunsOn = "ubuntu-latest"; - jobs.job = { - branches.default = { - changes.paths = [ - "config/**" - "terraform/**" - ]; - triggers.onMergeRequest = true; + jobs = { + job-a = { + branches.default = { + changes.paths = [ + "config/**" + "terraform/**" + ]; + triggers.onMergeRequest = true; + }; + }; + job-b = { + branches.default = { + triggers.onMergeRequest = true; + }; }; }; }; @@ -138,15 +145,22 @@ { id = "diff"; shell = "bash"; - env.PATHS = "job:config/**\\|terraform/**"; + env.PATHS = "job-a:config/**\\|terraform/**"; run = builtins.readFile ../../jobs/github-actions/diff-script; } ]; }; - job = { + job-a = { needs = [ "changes" ]; - "if" = ''''${{ fromJSON(needs.changes.outputs.changes)['job'] == true }}''; + "if" = ''''${{ fromJSON(needs.changes.outputs.changes)['job-a'] == true }}''; + runs-on = "ubuntu-latest"; + steps = [ + { uses = "actions/checkout@v4"; } + ]; + }; + + job-b = { runs-on = "ubuntu-latest"; steps = [ { uses = "actions/checkout@v4"; }