Skip to content

github_custom_actions.ActionBase

Base class for GitHub Actions.

You should implement main() method in the subclass.

You can define custom inputs and / or outputs types in the subclass. You can do nothing in the subclass if you don't need typed inputs and outputs.

Note these are just types, instances of these types are automatically created in the __init__ method.

Usage:

class MyInputs(ActionInputs):
    my_input: str
    '''My input description'''

    my_path: Path
    '''My path description'''

class MyOutputs(ActionOutputs):
    runner_os: str
    '''Runner OS description'''

class MyAction(ActionBase):
    inputs: MyInputs
    outputs: MyOutputs

    def main(self):
        if self.inputs.my_path is None:
            raise ValueError("my-path is required")
        self.inputs.my_path.mkdir(exist_ok=True)
        self.outputs.runner_os = self.env.runner_os
        self.summary.text += (
            self.render(
                "### {{ inputs.my_input }}.\n"
                "Have a nice day, {{ inputs['name'] }}!"
            )
        )

if __name__ == "__main__":
    MyAction().run()

Attributes

github_custom_actions.ActionBase.env instance-attribute

github_custom_actions.ActionBase.environment instance-attribute

environment = Environment(loader=FileSystemLoader(str(templates_dir)))

github_custom_actions.ActionBase.inputs instance-attribute

inputs: ActionInputs = types['inputs']()

github_custom_actions.ActionBase.outputs instance-attribute

outputs: ActionOutputs = types['outputs']()

github_custom_actions.ActionBase.summary class-attribute instance-attribute

summary = FileTextProperty('github_step_summary')

Functions

github_custom_actions.ActionBase.main

main() -> None

Business logic of the action.

Is called by run() method.

github_custom_actions.ActionBase.render

render(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:

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

github_custom_actions.ActionBase.render_template

render_template(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:

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

github_custom_actions.ActionBase.run

run() -> None

Run the action.

run() calls the main() method of the action with the necessary boilerplate to catch and report exceptions.

Usage:

if __name__ == "__main__":
    MyAction().run()

main() is where you implement the business logic of your action.