Skip to content

Render

github_custom_actions.ActionBase.render(template, **kwargs)

Render the template from the string with Jinja.

kwargs are the template context variables.

Also includes to the context the action's inputs, outputs, and env.

So you can use something like:

self.render("### {{ inputs.name }}!\nHave a nice day!")

Source code in src/github_custom_actions/action_base.py
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
def render(self, template: str, **kwargs: Any) -> str:
    """Render the template from the string with Jinja.

    `kwargs` are the template context variables.

    Also includes to the context the action's `inputs`, `outputs`, and `env`.

    So you can use something like:
    ```python
    self.render("### {{ inputs.name }}!\\nHave a nice day!")
    ```

    """
    return Template(template.replace("\\n", "\n")).render(
        env=self.env,
        inputs=self.inputs,
        outputs=self.outputs,
        **kwargs,
    )

github_custom_actions.ActionBase.render_template(template_name, **kwargs)

Render template from the templates directory.

template_name is the name of the template file without the extension. kwargs are the template context variables.

Also includes to the context the action's inputs, outputs, and env.

Usage:

self.render_template("executor.json", image="ubuntu-latest")

Source code in src/github_custom_actions/action_base.py
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
def render_template(self, template_name: str, **kwargs: Any) -> str:
    """Render template from the `templates` directory.

    `template_name` is the name of the template file without the extension.
    `kwargs` are the template context variables.

    Also includes to the context the action's `inputs`, `outputs`, and `env`.

    Usage:
    ```python
    self.render_template("executor.json", image="ubuntu-latest")
    ```
    """
    template = self.environment.get_template(template_name)
    return template.render(
        env=self.env,
        inputs=self.inputs,
        outputs=self.outputs,
        **kwargs,
    )