From 533bd2eef5f08da8076524fce0f0c9e1b7e00b42 Mon Sep 17 00:00:00 2001 From: technofab Date: Tue, 10 Sep 2024 13:07:48 +0000 Subject: [PATCH] feat: add assertion to check if a job's stage exists --- README.md | 2 +- lib/flakeModule.nix | 38 ++++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 39949b4..c005548 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ which can be imported in multiple projects. ]; ... - perSystem = {...}: { + perSystem = {pkgs, ...}: { ci = { stages = ["test"]; jobs = { diff --git a/lib/flakeModule.nix b/lib/flakeModule.nix index 8d6f4a9..7a5676c 100644 --- a/lib/flakeModule.nix +++ b/lib/flakeModule.nix @@ -54,6 +54,7 @@ }; stage = mkOption { type = types.str; + default = "test"; }; image = mkOption { type = types.str; @@ -171,25 +172,26 @@ jobsPatched = mapAttrs (key: job: { name = key; - value = builtins.removeAttrs ( - (prependToBeforeScript [ - "source setup_nix_ci ${key}" - ] - (prependToAfterScript [ - "finalize_nix_ci" + value = assert lib.assertMsg (builtins.elem job.stage (rest.stages or [])) "stage '${job.stage}' of job '${key}' does not exist"; + builtins.removeAttrs ( + (prependToBeforeScript [ + "source setup_nix_ci ${key}" ] - job)) - // lib.optionalAttrs job.nix { - image = job.image; - variables = lib.concatMapAttrs (name: value: - if lib.hasInfix "/nix/store/" value - then {} - else { - ${name} = value; - }) - (job.variables or {}); - } - ) ["nix" "deps"]; + (prependToAfterScript [ + "finalize_nix_ci" + ] + job)) + // lib.optionalAttrs job.nix { + image = job.image; + variables = lib.concatMapAttrs (name: value: + if lib.hasInfix "/nix/store/" value + then {} + else { + ${name} = value; + }) + (job.variables or {}); + } + ) ["nix" "deps"]; }) jobs; in