Skip to content

Workflow

The Workflow class is the top-level model that maps to a complete GitHub Actions workflow YAML file. It contains the workflow name, triggers, permissions, environment variables, defaults, concurrency settings, and jobs.

from ghagen import Workflow, On, Job, Step
from ghagen.models.trigger import PushTrigger
workflow = Workflow(
name="CI",
on=On(push=PushTrigger(branches=["main"])),
jobs={
"test": Job(
runs_on="ubuntu-latest",
steps=[Step(uses="actions/checkout@v4")],
),
},
)
print(workflow.to_yaml())
ParameterTypeDefaultDescription
namestr | NoneNoneThe display name of the workflow.
run_namestr | NoneNoneCustom name for workflow runs. Supports GitHub Actions expressions. Serialized as run-name.
onOn | dict | NoneNoneTrigger configuration for the workflow. See Triggers.
permissionsPermissions | Literal["read-all", "write-all"] | Raw[str] | NoneNoneToken permissions. Can be a Permissions object or a string shorthand. See Permissions.
envdict[str, str] | NoneNoneEnvironment variables available to all jobs in the workflow.
defaultsDefaults | NoneNoneDefault settings for all run steps. See Defaults.
concurrencystr | Concurrency | NoneNoneConcurrency group configuration. Can be a string (group name) or a Concurrency object.
jobsdict[str, Job]{}Map of job IDs to job definitions. See Job.

All models also accept these inherited parameters from the base class:

ParameterTypeDefaultDescription
extrasdict[str, Any]{}Arbitrary key/value pairs merged into YAML output for fields not covered by the typed API.
post_processCallable | NoneNoneCallback to modify the YAML mapping before emission. See Escape Hatches.
commentstr | NoneNoneBlock comment emitted above this node in the YAML output.
eol_commentstr | NoneNoneEnd-of-line comment for this node.

Per-field comments are attached by wrapping individual field values with with_comment() or with_eol_comment(). See Comments.

to_yaml(header=None, include_header=True) -> str

Section titled “to_yaml(header=None, include_header=True) -> str”

Generate the complete YAML string for this workflow.

ArgumentTypeDefaultDescription
headerstr | NoneNoneCustom header comment template. May contain {variable} placeholders. If None, uses the default ghagen header.
include_headerboolTrueWhether to include the header comment at the top of the file.

Returns the complete YAML string.

to_yaml_file(path, header=None, include_header=True) -> None

Section titled “to_yaml_file(path, header=None, include_header=True) -> None”

Write the workflow YAML to a file. Creates parent directories if they don’t exist.

ArgumentTypeDefaultDescription
pathstr | PathrequiredFile path to write to.
headerstr | NoneNoneCustom header comment template. See to_yaml() for details.
include_headerboolTrueWhether to include the header comment.

Default settings for all run steps in a job or workflow.

ParameterTypeDefaultDescription
runDefaultsRun | NoneNoneDefault run step settings.

Default shell and working directory for run steps.

ParameterTypeDefaultDescription
shellstr | Raw[str] | NoneNoneDefault shell for run steps (e.g., "bash", "pwsh").
working_directorystr | NoneNoneDefault working directory. Serialized as working-directory.

Concurrency configuration for workflows or jobs. Prevents concurrent runs in the same group.

ParameterTypeDefaultDescription
groupstrrequiredConcurrency group name. Supports expressions.
cancel_in_progressbool | NoneNoneWhether to cancel in-progress runs when a new run is queued. Serialized as cancel-in-progress.