Use columns for a single line; GitHub drops column properties for annotations
spanning multiple lines. Pass normal text—command helpers handle escaping.
See the workflow command reference.
Groups and command control
Group related logs
with gha.group("Run checks"):
gha.echo("Checking formatting")
gha.echo("Checking types")
The group closes even if the body raises. For manual control, use
start_group(title) and end_group().
Mask sensitive values
gha.add_mask("example-secret-value")
gha.echo("example-secret-value") # GitHub displays the registered value as ***.
Register masks before printing sensitive values.
Suspend command processing
echo() prints raw text, so command-looking text can be interpreted by GitHub.
Use stop_commands() when printing text that should stay literal:
with gha.stop_commands():
gha.echo("::warning::This remains plain text")
Processing resumes even if the body raises. For manual control:
stop_commands(token=None) and begin_stop_commands(token=None) generate random
UUID4 tokens by default. Custom tokens must be unique for the run; prefer the
generated token.
Register problem matchers
Problem matchers turn matching tool output into annotations.
remove_problem_matcher(*, owner=None, path=None) requires exactly one
selector. Use path=".github/matchers/compiler.json" to remove matchers from a file.
Relative matcher paths resolve against the workspace.
Example matcher file: .github/matchers/compiler.json
Set an output for later steps using the producing step's id.
set_env(name, value)
Set an environment variable for later steps in the same job.
get_env(name)
Read the process environment first, then the current step's pending environment file. Missing values return None; an empty process value takes precedence.
get_workflow_environment_variables()
Read pending values from this step's GITHUB_ENV file. Returns a fresh dictionary, or {} when the path is unset/empty.
Lists, tuples, and dictionaries become JSON; other values use str(). File
values preserve Unicode, whitespace, percent signs, and line breaks. Use nonempty
string names without =, <<, CR, LF, or NUL.
Scope:set_env() does not change this Python process's os.environ or
gha.vars. The pending file contains only this step's queued variables. GitHub
protects GITHUB_*/RUNNER_* variables and blocks NODE_OPTIONS through GITHUB_ENV.
Add directories to PATH
from pathlib import Path
gha.add_system_path(Path.cwd() / "tools", strict=True)
add_system_path(path, *, strict=False) accepts strings and text PathLike
objects. Directories become available in later steps; the current process's
PATH stays unchanged. A directory need not exist yet. strict=True requires one
nonempty entry without CR, LF, or NUL. The default preserves legacy path batches;
NUL is always rejected.
Write job summaries
Function
Behavior
append_job_summary(markdown_text)
Append Markdown and a newline.
overwrite_job_summary(markdown_text)
Replace this step's summary with Markdown and a newline.
remove_job_summary()
Delete this step's summary; a missing file is harmless.
if gha.is_github_action():
gha.notice("Running in GitHub Actions")
else:
print("Running locally")
Detection checks GITHUB_ACTIONS == "true" on every call. File-writing helpers
need their runner-provided file paths; missing paths raise KeyError and file
errors propagate.
Read live environment views
print(gha.vars.github.repository) # str or None
print(gha.vars.github.run_number) # str or None; numbers stay strings
print(gha.vars.runner.os) # str or None
print(gha.vars.runner.debug) # bool
vars reads os.environ on access. Properties are read-only; missing text is
None and empty text stays "". Boolean flags use exact values:
The public classes WorkflowVariables, GitHubVariables, and RunnerVariables
can also be used as type annotations or instantiated as separate views.
All environment properties
Property names map to their uppercase environment names: for example,
vars.github.run_id reads GITHUB_RUN_ID and vars.runner.tool_cache reads
RUNNER_TOOL_CACHE.
This Python view is separate from GitHub's workflow-expression
vars context,
which holds configuration variables. Import it explicitly (gha.vars or
from github_action_utils import vars); wildcard imports preserve built-in vars().
Read the event payload
payload = gha.event_payload()
print(payload.get("action"))
gha.event_payload.cache_clear() # Reload on the next call.
event_payload() loads UTF-8 JSON from GITHUB_EVENT_PATH and caches the result.
Calls share the same mutable object. Use .cache_info() for cache statistics.
Action state
Function
Behavior
save_state(name, value)
Save a value for another lifecycle hook of the same action.
get_state(name)
Read STATE_<name> in the receiving hook; returns None when absent.
In the action's main hook:
gha.save_state("cleanup_path", "/tmp/build")
In its post hook:
cleanup_path = gha.get_state("cleanup_path")
State uses the same value conversion as step data. It is scoped to
an action's pre/main/post lifecycle. Local actions support main/post hooks.
Use outputs or environment variables to share values between ordinary steps.
GitHub state documentation
Artifact identities
[!IMPORTANT]
These APIs need the runner's conditional artifact-file feature. Exposed file
paths alone do not prove support. Declarations record identities; they do not
upload files, push images, or sign artifacts.
Function or type
Behavior
declare_file_artifact(path)
Queue a plain file path. The runner resolves relative paths against the workspace and computes its identity after the step.
declare_oci_artifact(reference)
Queue an OCI reference with a full sha256, sha384, or sha512 digest (64, 96, or 128 hex characters). An oci:// prefix is optional; digest hex is normalized to lowercase.
get_workflow_artifacts()
Read fresh version-1 metadata as a tuple of immutable ArtifactSubject values. An empty subjects list returns ().
ArtifactSubject(name, digest, kind)
A named tuple with name, digest (algorithm:hex), and kind ("file" or "oci").
On a supported runner:
gha.declare_file_artifact("dist/app.whl")
gha.declare_oci_artifact(
"ghcr.io/example/app@sha256:" + "a" * 64
) # Use your image's real digest.
In a later step:
for subject in gha.get_workflow_artifacts():
print(subject.name, subject.digest, subject.kind)
Missing artifact-file configuration raises RuntimeError; empty/malformed or
unsupported metadata raises ValueError. File errors propagate. See GitHub's
artifact command documentation.
Configuration
Console helpers accept use_subprocess=False. To emit a message through a child
Python process without invoking a shell:
gha.echo("Hello", use_subprocess=True)
Set gha.COMMANDS_USE_SUBPROCESS = True for all console helpers. The global flag
wins over a per-call False. The COMMANDS_USE_SUBPROCESS environment variable is
read once at import: any nonempty string enables it, including "false" and
"0". Set the module flag to False to disable that global setting.
Compatibility and validation details
Python 3.11+ is required. Existing 1.1.0 package functions and call signatures
remain available. See the upgrade notes
for behavior changes.
The old boolean use_subprocess argument on set_output() and save_state()
emits DeprecationWarning; both helpers always write runner files.
Pending environment reads accept simple and multiline records, including a
leading UTF-8 BOM. Later duplicate names win; malformed records raise ValueError.
File-command names are validated before writing. Artifact declarations also
reject CR/LF/NUL, =, and trailing whitespace.
Custom stop tokens reject literal spaces, CR/LF/NUL, ::, trailing :, and
reserved workflow-command names. Invalid tokens are rejected before emission.
CommandTypes and LogCommandTypes are public typing aliases.
COMMAND_MARKER and the legacy ACTION_ENV_DELIMITER remain available;
file writers generate their own collision-checked delimiters.
Development
Development uses Python 3.15, uv, Ruff, strict mypy, pytest, and tox. CI covers
Python 3.11–3.15 on Linux, Windows, and macOS. The
feature showcase demonstrates every public
function, with automated checks, manual display checks, and conditional skips.