Skip to content

Reference

github_custom_actions

Python package for creating custom GitHub Actions.

The file is mandatory for build system to find the package.

Classes

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.

github_custom_actions.ActionInputs

Bases: EnvAttrDictVars

GitHub Action input variables.

Usage:

class MyInputs(ActionInputs):
    my_input: str

action = ActionBase(inputs=MyInputs())
print(action.inputs.my_input)
print(action.inputs["my-input"])  # the same as above

With attributes, you can only access explicitly declared vars, with dict-like access you can access any var. This way you can find your balance between strictly defined vars and flexibility.

Attribute names are converted to kebab-case. So action.inputs.my_input is the same as action.inputs["my-input"].

If you need to access a snake_case named input my_input, you should use dict-style only: action.inputs["my_input"]. But it's common to use kebab-case in GitHub Actions input names.

By GitHub convention, all input names are upper-cased in the environment and prefixed with "INPUT_". So actions.inputs.my_input or actions.inputs['my-input'] will be the variable INPUT_MY-INPUT in the environment. The ActionInputs does the conversion automatically.

Uses lazy loading of the values. So the value is read from the environment only when accessed and only once, and saved in the object's internal dict.

github_custom_actions.ActionOutputs

Bases: FileAttrDictVars

GitHub Actions output variables.

Usage:

class MyOutputs(ActionOutputs):
    my_output: str

action = ActionBase(outputs=MyOutputs())
action.outputs["my-output"] = "value"
action.outputs.my_output = "value"  # the same as above

With attributes, you can only access explicitly declared vars, with dict-like access you can access any var. This way you can find your balance between strictly defined vars and flexibility.

Attribute names are converted to kebab-case. So action.outputs.my_output is the same as action.outputs["my-output"].

If you need to access a snake_case named output like my_output you should use dict-style only: action.outputs["my_output"]. But it's common to use kebab-case in GitHub Actions output names.

Each output var assignment changes the GitHub outputs file (the path is defined as action.env.github_output).

github_custom_actions.GithubVars

Bases: EnvAttrDictVars

GitHub Action environment variables.

https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

Usage:

class MyAction:
    @property
    def env(self):
        return GithubVars()

action = MyAction()
print(action.env.github_repository)

Thanks to the docstrings your IDE will provide you with doc hints when you hover over the property. We do not load the attributes on the class init but do it Lazily. Once read, the value is stored in the instance dictionary and is not extracted from env anymore.

Converts attribute names to uppercase. Leave dict-style names unchanged.

Paths and files have type Path.

Attributes
github_custom_actions.GithubVars.CI instance-attribute
CI: str

Always set to true.

github_custom_actions.GithubVars.github_action instance-attribute
github_action: str

The name of the action currently running, or the id of a step. For example, for an action, __repo-owner_name-of-action-repo. GitHub removes special characters, and uses the name __run when the current step runs a script without an id. If you use the same script or action more than once in the same job, the name will include a suffix that consists of the sequence number preceded by an underscore. For example, the first script you run will have the name __run, and the second script will be named __run_2. Similarly, the second invocation of actions/checkout will be actionscheckout2.

github_custom_actions.GithubVars.github_action_path instance-attribute
github_action_path: Path

The path where an action is located. This property is only supported in composite actions. You can use this path to change directories to where the action is located and access other files in that same repository. For example, /home/runner/work/_actions/repo-owner/name-of-action-repo/v1.

github_custom_actions.GithubVars.github_action_repository instance-attribute
github_action_repository: str

For a step executing an action, this is the owner and repository name of the action. For example, actions/checkout.

github_custom_actions.GithubVars.github_actions instance-attribute
github_actions: str

Always set to true when GitHub Actions is running the workflow. You can use this variable to differentiate when tests are being run locally or by GitHub Actions.

github_custom_actions.GithubVars.github_actor instance-attribute
github_actor: str

The name of the person or app that initiated the workflow. For example, octocat.

github_custom_actions.GithubVars.github_actor_id instance-attribute
github_actor_id: str

The account ID of the person or app that triggered the initial workflow run. For example, 1234567. Note that this is different from the actor username.

github_custom_actions.GithubVars.github_api_url instance-attribute
github_api_url: str

Returns the API URL. For example: https://api.github.com.

github_custom_actions.GithubVars.github_base_ref instance-attribute
github_base_ref: str

The name of the base ref or target branch of the pull request in a workflow run. This is only set when the event that triggers a workflow run is either pull_request or pull_request_target. For example, main.

github_custom_actions.GithubVars.github_env instance-attribute
github_env: str

The path on the runner to the file that sets variables from workflow commands. This file is unique to the current step and changes for each step in a job. For example, /home/runner/work/_temp/_runner_file_commands/set_env_87406d6e-4979-4d42-98e1-3dab1f48b13a. For more information, see "Workflow commands for GitHub Actions".

github_custom_actions.GithubVars.github_event_name instance-attribute
github_event_name: str

The name of the event that triggered the workflow. For example, workflow_dispatch.

github_custom_actions.GithubVars.github_event_path instance-attribute
github_event_path: Path

The path to the file on the runner that contains the full event webhook payload. For example, /github/workflow/event.json.

github_custom_actions.GithubVars.github_graphql_url instance-attribute
github_graphql_url: str

Returns the GraphQL API URL. For example: https://api.github.com/graphql.

github_custom_actions.GithubVars.github_head_ref instance-attribute
github_head_ref: str

The head ref or source branch of the pull request in a workflow run. This property is only set when the event that triggers a workflow run is either pull_request or pull_request_target. For example, feature-branch-1.

github_custom_actions.GithubVars.github_job instance-attribute
github_job: str

The job_id of the current job. For example, greeting_job.

github_custom_actions.GithubVars.github_output instance-attribute
github_output: Path

The path on the runner to the file that sets the current step's outputs from workflow commands. This file is unique to the current step and changes for each step in a job. For example, /home/runner/work/_temp/_runner_file_commands/set_output_a50ef383-b063-46d9-9157-57953fc9f3f0. For more information, see "Workflow commands for GitHub Actions".

github_custom_actions.GithubVars.github_path instance-attribute
github_path: Path

The path on the runner to the file that sets system PATH variables from workflow commands. This file is unique to the current step and changes for each step in a job. For example, /home/runner/work/_temp/_runner_file_commands/add_path_899b9445-ad4a-400c-aa89-249f18632cf5. For more information, see "Workflow commands for GitHub Actions".

github_custom_actions.GithubVars.github_ref instance-attribute
github_ref: str

The fully-formed ref of the branch or tag that triggered the workflow run. For workflows triggered by push, this is the branch or tag ref that was pushed. For workflows triggered by pull_request, this is the pull request merge branch. For workflows triggered by release, this is the release tag created. For other triggers, this is the branch or tag ref that triggered the workflow run. This is only set if a branch or tag is available for the event type. The ref given is fully-formed, meaning that for branches the format is refs/heads/, for pull requests it is refs/pull//merge, and for tags it is refs/tags/. For example, refs/heads/feature-branch-1.

github_custom_actions.GithubVars.github_ref_name instance-attribute
github_ref_name: str

The short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example, feature-branch-1. For pull requests, the format is /merge.

github_custom_actions.GithubVars.github_ref_protected instance-attribute
github_ref_protected: str

true if branch protections or rulesets are configured for the ref that triggered the workflow run.

github_custom_actions.GithubVars.github_ref_type instance-attribute
github_ref_type: str

The type of ref that triggered the workflow run. Valid values are branch or tag.

github_custom_actions.GithubVars.github_repository instance-attribute
github_repository: str

The owner and repository name. For example, octocat/Hello-World.

github_custom_actions.GithubVars.github_repository_id instance-attribute
github_repository_id: str

The ID of the repository. For example, 123456789. Note that this is different from the repository name.

github_custom_actions.GithubVars.github_repository_owner instance-attribute
github_repository_owner: str

The repository owner's name. For example, octocat.

github_custom_actions.GithubVars.github_repository_owner_id instance-attribute
github_repository_owner_id: str

The repository owner's account ID. For example, 1234567. Note that this is different from the owner's name.

github_custom_actions.GithubVars.github_retention_days instance-attribute
github_retention_days: str

The number of days that workflow run logs and artifacts are kept. For example, 90.

github_custom_actions.GithubVars.github_run_attempt instance-attribute
github_run_attempt: str

A unique number for each attempt of a particular workflow run in a repository. This number begins at 1 for the workflow run's first attempt, and increments with each re-run. For example, 3.

github_custom_actions.GithubVars.github_run_id instance-attribute
github_run_id: str

A unique number for each workflow run within a repository. This number does not change if you re-run the workflow run. For example, 1658821493.

github_custom_actions.GithubVars.github_run_number instance-attribute
github_run_number: str

A unique number for each run of a particular workflow in a repository. This number begins at 1 for the workflow's first run, and increments with each new run. This number does not change if you re-run the workflow run. For example, 3.

github_custom_actions.GithubVars.github_server_url instance-attribute
github_server_url: str

The URL of the GitHub server. For example: https://github.com.

github_custom_actions.GithubVars.github_sha instance-attribute
github_sha: str

The commit SHA that triggered the workflow. The value of this commit SHA depends on the event that triggered the workflow. For more information, see "Events that trigger workflows." For example, ffac537e6cbbf934b08745a378932722df287a53.

github_custom_actions.GithubVars.github_step_summary instance-attribute
github_step_summary: Path

The path on the runner to the file that contains job summaries from workflow commands. This file is unique to the current step and changes for each step in a job. For example, /home/runner/_layout/_work/_temp/_runner_file_commands/step_summary_1cb22d7f-5663-41a8- 9ffc-13472605c76c. For more information, see "Workflow commands for GitHub Actions".

github_custom_actions.GithubVars.github_triggering_actor instance-attribute
github_triggering_actor: str

The username of the user that initiated the workflow run. If the workflow run is a re-run, this value may differ from github.actor. Any workflow re-runs will use the privileges of github.actor, even if the actor initiating the re-run (github.triggering_actor) has different privileges.

github_custom_actions.GithubVars.github_workflow instance-attribute
github_workflow: str

The name of the workflow. For example, My test workflow. If the workflow file doesn't specify a name, the value of this variable is the full path of the workflow file in the repository.

github_custom_actions.GithubVars.github_workflow_ref instance-attribute
github_workflow_ref: str

The ref path to the workflow. For example, octocat/hello-world/.github/workflows/my-workflow.yml@ refs/heads/my_branch.

github_custom_actions.GithubVars.github_workflow_sha instance-attribute
github_workflow_sha: str

The commit SHA for the workflow file.

github_custom_actions.GithubVars.github_workspace instance-attribute
github_workspace: Path

The default working directory on the runner for steps, and the default location of your repository when using the checkout action. For example, /home/runner/work/my-repo-name/my-repo-name.

github_custom_actions.GithubVars.runner_arch instance-attribute
runner_arch: str

The architecture of the runner executing the job. Possible values are X86, X64, ARM, or ARM64.

github_custom_actions.GithubVars.runner_debug instance-attribute
runner_debug: str

This is set only if debug logging is enabled, and always has the value of 1. It can be useful as an indicator to enable additional debugging or verbose logging in your own job steps.

github_custom_actions.GithubVars.runner_name instance-attribute
runner_name: str

The name of the runner executing the job. This name may not be unique in a workflow run as runners at the repository and organization levels could use the same name. For example, Hosted Agent

github_custom_actions.GithubVars.runner_os instance-attribute
runner_os: str

The operating system of the runner executing the job. Possible values are Linux, Windows, or macOS. For example, Windows

github_custom_actions.GithubVars.runner_temp instance-attribute
runner_temp: Path

The path to a temporary directory on the runner. This directory is emptied at the beginning and end of each job. Note that files will not be removed if the runner's user account does not have permission to delete them. For example, D:\a_temp

github_custom_actions.GithubVars.runner_tool_cache instance-attribute
runner_tool_cache: str

The path to the directory containing preinstalled tools for GitHub-hosted runners. For more information, see "Using GitHub-hosted runners". For example, C:\hostedtoolcache\windows

Modules

github_custom_actions.action_base

Classes
github_custom_actions.action_base.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.action_base.ActionBase.env instance-attribute
github_custom_actions.action_base.ActionBase.environment instance-attribute
environment = Environment(loader=FileSystemLoader(str(templates_dir)))
github_custom_actions.action_base.ActionBase.inputs instance-attribute
inputs: ActionInputs = types['inputs']()
github_custom_actions.action_base.ActionBase.outputs instance-attribute
outputs: ActionOutputs = types['outputs']()
github_custom_actions.action_base.ActionBase.summary class-attribute instance-attribute
summary = FileTextProperty('github_step_summary')
Functions
github_custom_actions.action_base.ActionBase.main
main() -> None

Business logic of the action.

Is called by run() method.

github_custom_actions.action_base.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.action_base.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.action_base.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.

github_custom_actions.action_base.FileTextProperty

Property descriptor read / write from a file.

Attributes
github_custom_actions.action_base.FileTextProperty.var_name instance-attribute
var_name = var_name

github_custom_actions.attr_dict_vars

Classes
github_custom_actions.attr_dict_vars.AttrDictVars

Common base class for accessing variables as attributes or dict.

github_custom_actions.env_attr_dict_vars

Classes
github_custom_actions.env_attr_dict_vars.EnvAttrDictVars

Bases: AttrDictVars

Dual access env vars.

Access to env vars as object attributes or as dict items. Do not allow changing vars, so this is a read-only source of env vars values.

With attributes, you can only access explicitly declared vars, with dict-like access you can access any var. This way you can find your balance between strictly defined vars and flexibility.

Usage:

class MyVars(EnvAttrDictVars):
    documented_var: str

vars = MyVars(prefix="INPUT_")
print(vars["undocumented_var"])  # from os.environ["INPUT_UNDOCUMENTED_VAR"]
print(vars.documented_var)  # from os.environ["INPUT_DOCUMENTED-VAR"]

Attribute names are converted with the method _attr_to_var_name() - it converts Python attribute names from snake_case to kebab-case.

github_custom_actions.file_attr_dict_vars

Classes
github_custom_actions.file_attr_dict_vars.FileAttrDictVars

Bases: AttrDictVars, MutableMapping

Dual access vars in a file.

File contains vars as key=value lines. Access with attributes or as dict.

With attributes, you can only access explicitly declared vars, with dict-like access you can access any var. This way you can find your balance between strictly defined vars and flexibility.

Usage: class MyVars(FileAttrDictVars): documented_var: str

vars = MyVars(Path("my_vars.txt")) vars["undocumented_var"] = "value1" vars.documented_var == "value2"

# Produces "my_vars.txt" with: # documented-var=value2 # undocumented_var=value1

On read/write, it converts var names with _name_from_external()/_external_name() methods. They remove/add _external_name_prefix to the names.

Attribute access also uses _attr_to_var_name() - by default it converts Python attribute names from snake_case to kebab-case.

github_custom_actions.github_vars

Classes
github_custom_actions.github_vars.GithubVars

Bases: EnvAttrDictVars

GitHub Action environment variables.

https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables

Usage:

class MyAction:
    @property
    def env(self):
        return GithubVars()

action = MyAction()
print(action.env.github_repository)

Thanks to the docstrings your IDE will provide you with doc hints when you hover over the property. We do not load the attributes on the class init but do it Lazily. Once read, the value is stored in the instance dictionary and is not extracted from env anymore.

Converts attribute names to uppercase. Leave dict-style names unchanged.

Paths and files have type Path.

Attributes
github_custom_actions.github_vars.GithubVars.CI instance-attribute
CI: str

Always set to true.

github_custom_actions.github_vars.GithubVars.github_action instance-attribute
github_action: str

The name of the action currently running, or the id of a step. For example, for an action, __repo-owner_name-of-action-repo. GitHub removes special characters, and uses the name __run when the current step runs a script without an id. If you use the same script or action more than once in the same job, the name will include a suffix that consists of the sequence number preceded by an underscore. For example, the first script you run will have the name __run, and the second script will be named __run_2. Similarly, the second invocation of actions/checkout will be actionscheckout2.

github_custom_actions.github_vars.GithubVars.github_action_path instance-attribute
github_action_path: Path

The path where an action is located. This property is only supported in composite actions. You can use this path to change directories to where the action is located and access other files in that same repository. For example, /home/runner/work/_actions/repo-owner/name-of-action-repo/v1.

github_custom_actions.github_vars.GithubVars.github_action_repository instance-attribute
github_action_repository: str

For a step executing an action, this is the owner and repository name of the action. For example, actions/checkout.

github_custom_actions.github_vars.GithubVars.github_actions instance-attribute
github_actions: str

Always set to true when GitHub Actions is running the workflow. You can use this variable to differentiate when tests are being run locally or by GitHub Actions.

github_custom_actions.github_vars.GithubVars.github_actor instance-attribute
github_actor: str

The name of the person or app that initiated the workflow. For example, octocat.

github_custom_actions.github_vars.GithubVars.github_actor_id instance-attribute
github_actor_id: str

The account ID of the person or app that triggered the initial workflow run. For example, 1234567. Note that this is different from the actor username.

github_custom_actions.github_vars.GithubVars.github_api_url instance-attribute
github_api_url: str

Returns the API URL. For example: https://api.github.com.

github_custom_actions.github_vars.GithubVars.github_base_ref instance-attribute
github_base_ref: str

The name of the base ref or target branch of the pull request in a workflow run. This is only set when the event that triggers a workflow run is either pull_request or pull_request_target. For example, main.

github_custom_actions.github_vars.GithubVars.github_env instance-attribute
github_env: str

The path on the runner to the file that sets variables from workflow commands. This file is unique to the current step and changes for each step in a job. For example, /home/runner/work/_temp/_runner_file_commands/set_env_87406d6e-4979-4d42-98e1-3dab1f48b13a. For more information, see "Workflow commands for GitHub Actions".

github_custom_actions.github_vars.GithubVars.github_event_name instance-attribute
github_event_name: str

The name of the event that triggered the workflow. For example, workflow_dispatch.

github_custom_actions.github_vars.GithubVars.github_event_path instance-attribute
github_event_path: Path

The path to the file on the runner that contains the full event webhook payload. For example, /github/workflow/event.json.

github_custom_actions.github_vars.GithubVars.github_graphql_url instance-attribute
github_graphql_url: str

Returns the GraphQL API URL. For example: https://api.github.com/graphql.

github_custom_actions.github_vars.GithubVars.github_head_ref instance-attribute
github_head_ref: str

The head ref or source branch of the pull request in a workflow run. This property is only set when the event that triggers a workflow run is either pull_request or pull_request_target. For example, feature-branch-1.

github_custom_actions.github_vars.GithubVars.github_job instance-attribute
github_job: str

The job_id of the current job. For example, greeting_job.

github_custom_actions.github_vars.GithubVars.github_output instance-attribute
github_output: Path

The path on the runner to the file that sets the current step's outputs from workflow commands. This file is unique to the current step and changes for each step in a job. For example, /home/runner/work/_temp/_runner_file_commands/set_output_a50ef383-b063-46d9-9157-57953fc9f3f0. For more information, see "Workflow commands for GitHub Actions".

github_custom_actions.github_vars.GithubVars.github_path instance-attribute
github_path: Path

The path on the runner to the file that sets system PATH variables from workflow commands. This file is unique to the current step and changes for each step in a job. For example, /home/runner/work/_temp/_runner_file_commands/add_path_899b9445-ad4a-400c-aa89-249f18632cf5. For more information, see "Workflow commands for GitHub Actions".

github_custom_actions.github_vars.GithubVars.github_ref instance-attribute
github_ref: str

The fully-formed ref of the branch or tag that triggered the workflow run. For workflows triggered by push, this is the branch or tag ref that was pushed. For workflows triggered by pull_request, this is the pull request merge branch. For workflows triggered by release, this is the release tag created. For other triggers, this is the branch or tag ref that triggered the workflow run. This is only set if a branch or tag is available for the event type. The ref given is fully-formed, meaning that for branches the format is refs/heads/, for pull requests it is refs/pull//merge, and for tags it is refs/tags/. For example, refs/heads/feature-branch-1.

github_custom_actions.github_vars.GithubVars.github_ref_name instance-attribute
github_ref_name: str

The short ref name of the branch or tag that triggered the workflow run. This value matches the branch or tag name shown on GitHub. For example, feature-branch-1. For pull requests, the format is /merge.

github_custom_actions.github_vars.GithubVars.github_ref_protected instance-attribute
github_ref_protected: str

true if branch protections or rulesets are configured for the ref that triggered the workflow run.

github_custom_actions.github_vars.GithubVars.github_ref_type instance-attribute
github_ref_type: str

The type of ref that triggered the workflow run. Valid values are branch or tag.

github_custom_actions.github_vars.GithubVars.github_repository instance-attribute
github_repository: str

The owner and repository name. For example, octocat/Hello-World.

github_custom_actions.github_vars.GithubVars.github_repository_id instance-attribute
github_repository_id: str

The ID of the repository. For example, 123456789. Note that this is different from the repository name.

github_custom_actions.github_vars.GithubVars.github_repository_owner instance-attribute
github_repository_owner: str

The repository owner's name. For example, octocat.

github_custom_actions.github_vars.GithubVars.github_repository_owner_id instance-attribute
github_repository_owner_id: str

The repository owner's account ID. For example, 1234567. Note that this is different from the owner's name.

github_custom_actions.github_vars.GithubVars.github_retention_days instance-attribute
github_retention_days: str

The number of days that workflow run logs and artifacts are kept. For example, 90.

github_custom_actions.github_vars.GithubVars.github_run_attempt instance-attribute
github_run_attempt: str

A unique number for each attempt of a particular workflow run in a repository. This number begins at 1 for the workflow run's first attempt, and increments with each re-run. For example, 3.

github_custom_actions.github_vars.GithubVars.github_run_id instance-attribute
github_run_id: str

A unique number for each workflow run within a repository. This number does not change if you re-run the workflow run. For example, 1658821493.

github_custom_actions.github_vars.GithubVars.github_run_number instance-attribute
github_run_number: str

A unique number for each run of a particular workflow in a repository. This number begins at 1 for the workflow's first run, and increments with each new run. This number does not change if you re-run the workflow run. For example, 3.

github_custom_actions.github_vars.GithubVars.github_server_url instance-attribute
github_server_url: str

The URL of the GitHub server. For example: https://github.com.

github_custom_actions.github_vars.GithubVars.github_sha instance-attribute
github_sha: str

The commit SHA that triggered the workflow. The value of this commit SHA depends on the event that triggered the workflow. For more information, see "Events that trigger workflows." For example, ffac537e6cbbf934b08745a378932722df287a53.

github_custom_actions.github_vars.GithubVars.github_step_summary instance-attribute
github_step_summary: Path

The path on the runner to the file that contains job summaries from workflow commands. This file is unique to the current step and changes for each step in a job. For example, /home/runner/_layout/_work/_temp/_runner_file_commands/step_summary_1cb22d7f-5663-41a8- 9ffc-13472605c76c. For more information, see "Workflow commands for GitHub Actions".

github_custom_actions.github_vars.GithubVars.github_triggering_actor instance-attribute
github_triggering_actor: str

The username of the user that initiated the workflow run. If the workflow run is a re-run, this value may differ from github.actor. Any workflow re-runs will use the privileges of github.actor, even if the actor initiating the re-run (github.triggering_actor) has different privileges.

github_custom_actions.github_vars.GithubVars.github_workflow instance-attribute
github_workflow: str

The name of the workflow. For example, My test workflow. If the workflow file doesn't specify a name, the value of this variable is the full path of the workflow file in the repository.

github_custom_actions.github_vars.GithubVars.github_workflow_ref instance-attribute
github_workflow_ref: str

The ref path to the workflow. For example, octocat/hello-world/.github/workflows/my-workflow.yml@ refs/heads/my_branch.

github_custom_actions.github_vars.GithubVars.github_workflow_sha instance-attribute
github_workflow_sha: str

The commit SHA for the workflow file.

github_custom_actions.github_vars.GithubVars.github_workspace instance-attribute
github_workspace: Path

The default working directory on the runner for steps, and the default location of your repository when using the checkout action. For example, /home/runner/work/my-repo-name/my-repo-name.

github_custom_actions.github_vars.GithubVars.runner_arch instance-attribute
runner_arch: str

The architecture of the runner executing the job. Possible values are X86, X64, ARM, or ARM64.

github_custom_actions.github_vars.GithubVars.runner_debug instance-attribute
runner_debug: str

This is set only if debug logging is enabled, and always has the value of 1. It can be useful as an indicator to enable additional debugging or verbose logging in your own job steps.

github_custom_actions.github_vars.GithubVars.runner_name instance-attribute
runner_name: str

The name of the runner executing the job. This name may not be unique in a workflow run as runners at the repository and organization levels could use the same name. For example, Hosted Agent

github_custom_actions.github_vars.GithubVars.runner_os instance-attribute
runner_os: str

The operating system of the runner executing the job. Possible values are Linux, Windows, or macOS. For example, Windows

github_custom_actions.github_vars.GithubVars.runner_temp instance-attribute
runner_temp: Path

The path to a temporary directory on the runner. This directory is emptied at the beginning and end of each job. Note that files will not be removed if the runner's user account does not have permission to delete them. For example, D:\a_temp

github_custom_actions.github_vars.GithubVars.runner_tool_cache instance-attribute
runner_tool_cache: str

The path to the directory containing preinstalled tools for GitHub-hosted runners. For more information, see "Using GitHub-hosted runners". For example, C:\hostedtoolcache\windows

github_custom_actions.inputs_outputs

Github Actions helper functions.

We want to support Python 3.7 that you still have on some self-hosted action runners. So no fancy features like walrus operator, @cached_property, etc.

Attributes
github_custom_actions.inputs_outputs.INPUT_PREFIX module-attribute
INPUT_PREFIX = 'INPUT_'
Classes
github_custom_actions.inputs_outputs.ActionInputs

Bases: EnvAttrDictVars

GitHub Action input variables.

Usage:

class MyInputs(ActionInputs):
    my_input: str

action = ActionBase(inputs=MyInputs())
print(action.inputs.my_input)
print(action.inputs["my-input"])  # the same as above

With attributes, you can only access explicitly declared vars, with dict-like access you can access any var. This way you can find your balance between strictly defined vars and flexibility.

Attribute names are converted to kebab-case. So action.inputs.my_input is the same as action.inputs["my-input"].

If you need to access a snake_case named input my_input, you should use dict-style only: action.inputs["my_input"]. But it's common to use kebab-case in GitHub Actions input names.

By GitHub convention, all input names are upper-cased in the environment and prefixed with "INPUT_". So actions.inputs.my_input or actions.inputs['my-input'] will be the variable INPUT_MY-INPUT in the environment. The ActionInputs does the conversion automatically.

Uses lazy loading of the values. So the value is read from the environment only when accessed and only once, and saved in the object's internal dict.

github_custom_actions.inputs_outputs.ActionOutputs

Bases: FileAttrDictVars

GitHub Actions output variables.

Usage:

class MyOutputs(ActionOutputs):
    my_output: str

action = ActionBase(outputs=MyOutputs())
action.outputs["my-output"] = "value"
action.outputs.my_output = "value"  # the same as above

With attributes, you can only access explicitly declared vars, with dict-like access you can access any var. This way you can find your balance between strictly defined vars and flexibility.

Attribute names are converted to kebab-case. So action.outputs.my_output is the same as action.outputs["my-output"].

If you need to access a snake_case named output like my_output you should use dict-style only: action.outputs["my_output"]. But it's common to use kebab-case in GitHub Actions output names.

Each output var assignment changes the GitHub outputs file (the path is defined as action.env.github_output).