{"id":4549,"library":"github-action-utils","title":"GitHub Action Utils","description":"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.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/saadmk11/github-action-utils","tags":["github actions","workflow commands","utilities","ci/cd","python"],"install":[{"cmd":"pip install github-action-utils","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"All functions","correct":"import github_action_utils as gha_utils"},{"symbol":"Specific functions","correct":"from github_action_utils import set_output, save_state, group"}],"quickstart":{"code":"import github_action_utils as gha_utils\nimport os\n\n# Example usage within a GitHub Action workflow\n# Outputs and state are typically picked up by the GitHub Actions runner.\n\n# Using a group to organize log output\nwith gha_utils.group(\"My Python Script Group\"):\n    # Set an output variable\n    gha_utils.set_output(\"my_output_key\", \"my_output_value\")\n    print(f\"Set output: my_output_key='my_output_value'\")\n\n    # Save a state variable (for subsequent jobs in the same workflow)\n    gha_utils.save_state(\"my_state_key\", \"my_state_value\")\n    print(f\"Saved state: my_state_key='my_state_value'\")\n\n    # Log messages with different severities\n    gha_utils.debug(\"This is a debug message.\")\n    gha_utils.notice(\"This is a notice message.\")\n    gha_utils.warning(\"This is a warning message.\", title=\"Python Warning\")\n    gha_utils.error(\"This is an error message.\", title=\"Python Error\")\n\n    # Append content to the job summary\n    gha_utils.append_job_summary(\"# Python Script Summary\\n\\n- Task A Completed\\n- Task B Completed\")\n    print(\"Appended to job summary.\")\n\n# Retrieve environment variables set by GitHub Actions\nrepo_owner = os.environ.get('GITHUB_REPOSITORY_OWNER', 'unknown_owner')\nprint(f\"Running in repository owned by: {repo_owner}\")\n","lang":"python","description":"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."},"warnings":[{"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.","message":"GitHub 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.","severity":"breaking","affected_versions":"<1.1.0"},{"fix":"Upgrade to `github-action-utils>=1.0.2` to ensure consistent handling of the `use_subprocess` parameter within the `group()` context manager.","message":"The `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.","severity":"gotcha","affected_versions":"<1.0.2"},{"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.","message":"By 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}