GitHub Action Utils

1.1.0 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →