Registry / devops / github-action-utils

github-action-utils

JSON →
library1.1.0pypypi✓ verified 23d ago

github-action-utils is a Python library (version 1.1.0) providing a collection of functions to execute GitHub Action Workflow Commands directly from Python scripts within a workflow run. This allows for programmatic control over aspects like setting outputs, saving state, logging, and job summaries. The library aims for a stable release cadence, typically updating to reflect changes in GitHub Actions' underlying command mechanisms.

pip install github-action-utils
INSTALL
IMPORT
SIG · GITHUB-ACTION-UTIL
G
github-action-utils
devopspythonv1.1.0
Install
1.5s avg
Import
31ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.032s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.030s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

All functions
import github_action_utils as gha_utils
Specific functions
from github_action_utils import set_output, save_state, group

This quickstart demonstrates how to use various utility functions provided by `github-action-utils` within a Python script running as part of a GitHub Action workflow. It covers setting outputs and state, logging messages at different levels, and appending content to the job summary. Outputs and state variables are automatically registered with the GitHub Actions runner.

import github_action_utils as gha_utils import os # Example usage within a GitHub Action workflow # Outputs and state are typically picked up by the GitHub Actions runner. # Using a group to organize log output with gha_utils.group("My Python Script Group"): # Set an output variable gha_utils.set_output("my_output_key", "my_output_value") print(f"Set output: my_output_key='my_output_value'") # Save a state variable (for subsequent jobs in the same workflow) gha_utils.save_state("my_state_key", "my_state_value") print(f"Saved state: my_state_key='my_state_value'") # Log messages with different severities gha_utils.debug("This is a debug message.") gha_utils.notice("This is a notice message.") gha_utils.warning("This is a warning message.", title="Python Warning") gha_utils.error("This is an error message.", title="Python Error") # Append content to the job summary gha_utils.append_job_summary("# Python Script Summary\n\n- Task A Completed\n- Task B Completed") print("Appended to job summary.") # Retrieve environment variables set by GitHub Actions repo_owner = os.environ.get('GITHUB_REPOSITORY_OWNER', 'unknown_owner') print(f"Running in repository owned by: {repo_owner}")
Debug
Known issues
breakingGitHub Actions deprecated the `::set-output::` and `::save-state::` commands via stdout, shifting to environment files (`$GITHUB_OUTPUT`, `$GITHUB_STATE`). The `github-action-utils` library updated its `set_output` and `save_state` implementations in version `1.1.0` to align with these new GitHub recommendations. While the function signatures in the library remained the same, the underlying mechanism changed.
fix
Upgrade to `github-action-utils>=1.1.0`. Ensure your workflow runners are up-to-date (version 2.298.2 or greater for warnings, and generally updated to avoid failures for direct stdout commands). Users relying on the *old internal behavior* of these functions might need to verify compatibility, though the library aims to provide the correct interface for the new GitHub spec.
affects: <1.1.0
gotchaThe `group()` context manager had a bug in versions prior to `1.0.2` where the `end_group()` function call might not correctly pass the `use_subprocess` parameter, leading to inconsistent behavior if subprocess execution was desired.
fix
Upgrade to `github-action-utils>=1.0.2` to ensure consistent handling of the `use_subprocess` parameter within the `group()` context manager.
affects: <1.0.2
gotchaBy default, `github-action-utils` might directly interact with GitHub Action workflow commands through standard output. In some highly restrictive or isolated environments, it might be necessary to force commands to run via Python's `subprocess` module. This can be controlled via the `use_subprocess` parameter in functions or the `COMMANDS_USE_SUBPROCESS` environment variable.
fix
If encountering issues with workflow commands not being recognized, try setting `use_subprocess=True` on individual function calls (e.g., `gha_utils.echo("msg", use_subprocess=True)`) or setting the environment variable `COMMANDS_USE_SUBPROCESS=true` for the workflow step.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'github_action_utils'
The `github-action-utils` library is not installed in the environment where the Python script is being run, or the import statement uses an incorrect module name.
fix
Install the library using pip: `pip install github-action-utils`. Ensure your import statement is `import github_action_utils` or `import github_action_utils as gha_utils`.
AttributeError: module 'github_action_utils' has no attribute 'set_ouptut'
A function name within the `github_action_utils` module was misspelled or the accessed attribute/function does not exist.
fix
Correct the function call to use the accurate name as defined in the library, for example, `gha_utils.set_output(...)` instead of `gha_utils.set_ouptut(...)`.
TypeError: set_output() missing 1 required positional argument: 'value'
A required argument for a `github_action_utils` function was not provided, or an incorrect number of arguments were passed.
fix
Ensure all required arguments, such as both `name` and `value` for `set_output`, are passed to the function. Example: `gha_utils.set_output("my_key", "my_value")`.
TypeError: argument 'message' must be str, not int
A `github_action_utils` function received an argument of an incorrect data type (e.g., an integer where a string was expected).
fix
Provide arguments of the correct type as expected by the function. For example, ensure messages for logging functions like `debug`, `warning`, or `error` are strings: `gha_utils.debug("This is a debug message")`.
Upgrade
Version history
1.1.0latest on PyPI · released Oct 17, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
Resources
github-action-utils — pip install github-action-utils · libregistry