feat: add assertion to check if a job's stage exists

This commit is contained in:
technofab 2024-09-10 13:07:48 +00:00
parent e3b35ec8ae
commit 533bd2eef5
2 changed files with 21 additions and 19 deletions

View file

@ -19,7 +19,7 @@ which can be imported in multiple projects.
]; ];
... ...
perSystem = {...}: { perSystem = {pkgs, ...}: {
ci = { ci = {
stages = ["test"]; stages = ["test"];
jobs = { jobs = {

View file

@ -54,6 +54,7 @@
}; };
stage = mkOption { stage = mkOption {
type = types.str; type = types.str;
default = "test";
}; };
image = mkOption { image = mkOption {
type = types.str; type = types.str;
@ -171,25 +172,26 @@
jobsPatched = jobsPatched =
mapAttrs (key: job: { mapAttrs (key: job: {
name = key; name = key;
value = builtins.removeAttrs ( value = assert lib.assertMsg (builtins.elem job.stage (rest.stages or [])) "stage '${job.stage}' of job '${key}' does not exist";
(prependToBeforeScript [ builtins.removeAttrs (
"source setup_nix_ci ${key}" (prependToBeforeScript [
] "source setup_nix_ci ${key}"
(prependToAfterScript [
"finalize_nix_ci"
] ]
job)) (prependToAfterScript [
// lib.optionalAttrs job.nix { "finalize_nix_ci"
image = job.image; ]
variables = lib.concatMapAttrs (name: value: job))
if lib.hasInfix "/nix/store/" value // lib.optionalAttrs job.nix {
then {} image = job.image;
else { variables = lib.concatMapAttrs (name: value:
${name} = value; if lib.hasInfix "/nix/store/" value
}) then {}
(job.variables or {}); else {
} ${name} = value;
) ["nix" "deps"]; })
(job.variables or {});
}
) ["nix" "deps"];
}) })
jobs; jobs;
in in