From f2aaa2230ca2aef1585877257abcafd7876ff7aa Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Wed, 8 Jan 2025 16:51:04 +0100 Subject: [PATCH] feat(module/workflow): Add a header to the start of generated files --- modules/workflows.nix | 44 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/modules/workflows.nix b/modules/workflows.nix index e117291..38048cf 100644 --- a/modules/workflows.nix +++ b/modules/workflows.nix @@ -25,6 +25,7 @@ let attrsOf bool enum + lines path str ; @@ -34,7 +35,13 @@ let cfg = config; generate = - name: value: + name: + { + + buildCheck, + rootSrc, + value, + }: runCommand "${name}.yaml" { nativeBuildInputs = [ @@ -43,21 +50,29 @@ let ]; value = builtins.toJSON value; - passAsFile = [ "value" ]; + inherit (cfg) header; + passAsFile = [ + "header" + "value" + ]; preferLocalBuild = true; } '' - json2yaml "$valuePath" "$out" - - # Check that the workflow is valid - cd "${cfg.rootSrc}" && action-validator "$out" - ''; + json2yaml "$valuePath" out + cat "$headerPath" out > "$out" + '' + + (optionalString buildCheck '' + # Check that the workflow is valid + cd "${rootSrc}" && action-validator "$out" + ''); install = name: value: let - result = - if cfg.buildCheck then generate name value else (pkgs.formats.yaml { }).generate name value; + result = generate name { + inherit value; + inherit (cfg) buildCheck rootSrc; + }; path = ".${cfg.platform}/workflows/${name}.yaml"; in '' @@ -121,6 +136,17 @@ in 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 = {