Action inputs and outputs should be defined inside the action.yml
first. This section can be summarized into three simple steps.
The following example shows that the action receives several input parameters.
...
inputs:
full_name:
description: First name
required: true
is_student:
description: Education status
required: true
birth_year:
description: Year of birth
required: false
To receive these inputs from the workflow, they should be defined as the arguments of the action function in the main.py
.
...
@workflow.action
def my_action(full_name: str, is_student: bool, birth_year: int) -> None:
...
Make sure your action function parameters are typed correctly.
To write output variables to the workflow, use the workflow.write()
method.
from pyaction.workflow.stream import WorkflowContext
...
@workflow.action
def my_action() -> None:
workflow.write(
WorkflowContext(
{
"var_1": "Foo",
"var_2": "Bar",
...
}
)
)
You can receive them by assigning an id
to the action step in the workflow.
steps:
- name: Running My Action
id: my_action
uses: username/my-action@v2
- name: Echoing The Values
run: |
echo ${{ steps.my_action.outputs.var_1 }} # = Foo
echo ${{ steps.my_action.outputs.var_2 }} # = Bar