Skip to content

The ActionBase base class also exposes helpers to emit the standard GitHub workflow log commands. Use debug(message: str) when you want to show extra information only when a workflow runs with debug logging enabled. For annotations that should show up in the PR “Files changed” view, call ActionBase.message() (or its convenience aliases error_message, notice_message, and warning_message) so you can attach file, line, and column information:

class MyAction(ActionBase):
    def main(self):
        self.debug("Finished parsing configuration")
        self.error_message(
            message="Unknown key 'service_port'",
            title="Invalid config",
            file="config.yml",
            line=14,
            column=1,
        )

Those helpers format the underlying ::<severity>:: workflow command for you; refer to the links above for the full list of keyword arguments if you need to build more complex annotations.

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.error_message class-attribute instance-attribute

error_message = partialmethod(message, 'error')

github_custom_actions.ActionBase.inputs instance-attribute

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

github_custom_actions.ActionBase.notice_message class-attribute instance-attribute

notice_message = partialmethod(message, 'notice')

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')

github_custom_actions.ActionBase.warning_message class-attribute instance-attribute

warning_message = partialmethod(message, 'warning')

Functions

github_custom_actions.ActionBase.debug staticmethod

debug(message: str)

Emits a debug message. The runner needs to be invoked with enabled debug logging to show these.

Example usage:

self.debug("Action invoked.")

github_custom_actions.ActionBase.main

main() -> None

Business logic of the action.

Is called by run() method.

github_custom_actions.ActionBase.message staticmethod

message(severity: Literal['error', 'notice', 'warning'], message: str, title: Optional[str] = None, file: Optional[str] = None, line: Optional[int] = None, column: Optional[int] = None, end_line: Optional[int] = None, end_column: Optional[int] = None)

Emits a message at the given severity level. The keyword arguments can be used to generate annotations that will be displayed within the Review section of a Pull Request. Refer to the messages related section in the workflows commands reference for semantic details.

There are also the methods error_message, notice_message and warning_message as shortcuts.

Example usages:

self.message("warning", "Deprecated input used: pattern")
# or equivalently:
self.warning_message("Deprecated input used: pattern")

self.error_message(
    "Value exceeds limit.",
    title="Schema error",
    file="config.yml",
    line=7,
    column=42
)

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.