@@ -45,6 +45,9 @@ _ATTRS = {
4545 "namespace" : attr .string (
4646 doc = "Namespace scope for this reques." ,
4747 ),
48+ "template_output" : attr .output (
49+ doc = "Filename to dump the rendered chart" ,
50+ ),
4851}
4952
5053def _impl (ctx ):
@@ -69,10 +72,21 @@ def _impl(ctx):
6972 is_executable = True ,
7073 )
7174
72- return DefaultInfo (
73- executable = executable ,
74- runfiles = ctx .runfiles (runfiles ),
75- )
75+ result = [DefaultInfo (executable = executable , runfiles = ctx .runfiles (runfiles ), files = depset ())]
76+
77+ if ctx .outputs .template_output :
78+ template_command = _build_template_command (ctx )
79+ ctx .actions .run_shell (
80+ inputs = [ctx .file .chart ],
81+ outputs = [ctx .outputs .template_output ],
82+ arguments = [ctx .outputs .template_output .path ],
83+ tools = ctx .toolchains ["@slamdev_rules_helm//helm:toolchain_type" ].default .files ,
84+ progress_message = "Rendering chart " + ctx .outputs .template_output .short_path ,
85+ command = template_command + " > $1" ,
86+ )
87+ result += [OutputGroupInfo (template = depset ([ctx .outputs .template_output ]))]
88+
89+ return result
7690
7791def _build_helm_command (ctx ):
7892 args = [ctx .var ["HELM_RUNFILES_BIN" ]]
@@ -100,6 +114,19 @@ def _build_helm_command(ctx):
100114 args .extend (["--namespace" , ctx .attr .namespace ])
101115 return " " .join (args )
102116
117+ def _build_template_command (ctx ):
118+ args = [ctx .var ["HELM_BIN" ]]
119+ args += ["template" ]
120+ args += [ctx .attr .release_name ]
121+ args += [ctx .file .chart .path ]
122+ if ctx .attr .disable_openapi_validation :
123+ args += ["--disable-openapi-validation" ]
124+ if ctx .attr .namespace :
125+ args += ["--namespace" , ctx .attr .namespace ]
126+ if ctx .attr .no_hooks :
127+ args += ["--no-hooks" ]
128+ return " " .join (args )
129+
103130install = rule (
104131 doc = _DOC ,
105132 implementation = _impl ,
0 commit comments