Skip to content

Step

The Step class represents a single step within a GitHub Actions job. A step either runs a shell command (run) or uses an action (uses).

from ghagen import Step
# Action step
checkout = Step(uses="actions/checkout@v4")
# Run step
test = Step(
name="Run tests",
run="pytest --verbose",
env={"CI": "true"},
)
# Conditional step
deploy = Step(
name="Deploy",
if_="github.ref == 'refs/heads/main'",
run="./deploy.sh",
)
ParameterTypeDefaultDescription
idstr | NoneNoneUnique identifier for the step. Used to reference step outputs in expressions (e.g., steps.<id>.outputs).
namestr | NoneNoneDisplay name for the step.
if_str | NoneNoneConditional expression that must evaluate to true for this step to run. Serialized as if.
usesstr | NoneNoneAction to use (e.g., "actions/checkout@v4"). Mutually exclusive with run.
runstr | NoneNoneShell command(s) to run. Multi-line strings are automatically dedented. Mutually exclusive with uses.
with_dict[str, Any] | NoneNoneInput parameters for the action specified by uses. Serialized as with.
envdict[str, str] | NoneNoneEnvironment variables for this step.
shellShellType | Raw[str] | NoneNoneShell to use for run commands. See ShellType.
working_directorystr | NoneNoneWorking directory for run commands. Serialized as working-directory.
continue_on_errorbool | str | NoneNoneAllow the job to continue when this step fails. Serialized as continue-on-error.
timeout_minutesint | NoneNoneMaximum minutes the step can run before being cancelled. Serialized as timeout-minutes.

All step instances also accept the base model parameters (extras, comment, eol_comment, post_process). Per-field comments are attached by wrapping field values with with_comment() or with_eol_comment(). See Workflow for details.

An enum of supported shell types for run steps. Use Raw[str] for shell types not covered by this enum.

from ghagen.models.common import ShellType
step = Step(run="echo hello", shell=ShellType.BASH)
ValueString
ShellType.BASH"bash"
ShellType.PWSH"pwsh"
ShellType.PYTHON"python"
ShellType.SH"sh"
ShellType.CMD"cmd"