Skip to content

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

Source code in src/github_custom_actions/inputs_outputs.py
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class ActionOutputs(FileAttrDictVars):
    """GitHub Actions output variables.

    Usage:
       ```python
       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`).
    """

    def __init__(self) -> None:
        super().__init__(Path(os.environ["GITHUB_OUTPUT"]))