feat(module/workflow): Add a header to the start of generated files
All checks were successful
Run pre-commit on all files / pre-push (push) Successful in 19s

This commit is contained in:
Tom Hubrecht 2025-01-08 16:51:04 +01:00
parent 829e83af9c
commit f2aaa2230c
Signed by: thubrecht
SSH key fingerprint: SHA256:CYNvFo44Ar9qCNnWNnvJVhs0QXO9AZjOLlPeWcSij3Q

View file

@ -25,6 +25,7 @@ let
attrsOf attrsOf
bool bool
enum enum
lines
path path
str str
; ;
@ -34,7 +35,13 @@ let
cfg = config; cfg = config;
generate = generate =
name: value: name:
{
buildCheck,
rootSrc,
value,
}:
runCommand "${name}.yaml" runCommand "${name}.yaml"
{ {
nativeBuildInputs = [ nativeBuildInputs = [
@ -43,21 +50,29 @@ let
]; ];
value = builtins.toJSON value; value = builtins.toJSON value;
passAsFile = [ "value" ]; inherit (cfg) header;
passAsFile = [
"header"
"value"
];
preferLocalBuild = true; preferLocalBuild = true;
} }
'' ''
json2yaml "$valuePath" "$out" json2yaml "$valuePath" out
cat "$headerPath" out > "$out"
# Check that the workflow is valid ''
cd "${cfg.rootSrc}" && action-validator "$out" + (optionalString buildCheck ''
''; # Check that the workflow is valid
cd "${rootSrc}" && action-validator "$out"
'');
install = install =
name: value: name: value:
let let
result = result = generate name {
if cfg.buildCheck then generate name value else (pkgs.formats.yaml { }).generate name value; inherit value;
inherit (cfg) buildCheck rootSrc;
};
path = ".${cfg.platform}/workflows/${name}.yaml"; path = ".${cfg.platform}/workflows/${name}.yaml";
in in
'' ''
@ -121,6 +136,17 @@ in
It introduces a dependency on the `rootSrc` directory. It introduces a dependency on the `rootSrc` directory.
''; '';
}; };
header = mkOption {
type = lines;
default = ''
###
# This file was automatically generated with nix-actions.
'';
description = ''
Text header to prepend to the generated workflow YAML file.
'';
};
}; };
config = { config = {