api
InArg(*, help, default=None)
¶
Force proper annotation of the input of a GitHub Action.
Should be used to declare the input arguments of an action. It returns
Any
to bypass mypy
's type checking. Similar to
pydantic.fields.Field but it is tailored to help us write the inputs for
an action and its steps.
Note
By default all input arguments are required. If you want to make an input not required then provide a default value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
help |
str
|
Human-readable description. |
required |
default |
str | None
|
The default value for the argument. |
None
|
Returns:
Type | Description |
---|---|
Any
|
A new |
Source code in m/github/actions/api.py
OutArg(*, help, export=False)
¶
Force proper annotation of the output of a GitHub Action.
Note
All steps have access to the steps output, if we want to make the output
available to the action we need to export
it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
help |
str
|
Human-readable description. |
required |
export |
bool
|
Whether the argument is to be exported to the action. |
False
|
Returns:
Type | Description |
---|---|
Any
|
A new |
Source code in m/github/actions/api.py
dump_step_outputs(outputs)
¶
Dump the outputs for a GitHub Action step.
Github does this if we write to the file where $GITHUB_OUTPUT is pointing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
outputs |
OutputModel
|
The outputs to dump. |
required |
Returns:
Type | Description |
---|---|
Res[int]
|
A |
Source code in m/github/actions/api.py
load_step_inputs(model)
¶
Load the GitHub Action inputs from the environment.
This function can be used provided that in the GitHub Action workflow we set up:::
env:
INPUT_ARG_1: ${{ inputs.arg-1 }}
In this way the inputs will set in the environment which we can then read in our main python function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
type[InputModel]
|
The class to create an instance of. |
required |
Returns:
Type | Description |
---|---|
Res[InputModel]
|
A |
Source code in m/github/actions/api.py
run_action(main)
¶
Entry point for a GitHub Action.
This is the main function that should be used to run an action. It takes in
a function that takes in a m.pydantic.KebabModel and returns a
Res[KebabModel]
.
The only place where this function is needed is in the the if block
mypy
will make sure that the you are providing the correct type of function
to run_action
. Keep in mind, the function is generic and we should be writing
models for the inputs and outputs for all of our functions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
main |
Callable[[InputModel], Res[OutputModel]]
|
The main function of the GitHub Action. |
required |