{"id":19115274,"url":"https://github.com/saadmk11/github-action-utils","last_synced_at":"2025-04-09T07:09:09.261Z","repository":{"id":46262108,"uuid":"515257446","full_name":"saadmk11/github-action-utils","owner":"saadmk11","description":"Collection of python functions that can be used to run GitHub Action Workflow Commands ","archived":false,"fork":false,"pushed_at":"2023-10-01T03:40:05.000Z","size":71,"stargazers_count":82,"open_issues_count":10,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T04:09:38.290Z","etag":null,"topics":["actions","github","github-action","github-actions","hacktoberfest","python","python-utilities","python3","python3-library","utility","utility-library","workflow","workflow-utility"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/github-action-utils/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saadmk11.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-18T16:17:46.000Z","updated_at":"2025-03-20T16:27:33.000Z","dependencies_parsed_at":"2024-06-19T05:42:56.501Z","dependency_job_id":null,"html_url":"https://github.com/saadmk11/github-action-utils","commit_stats":{"total_commits":49,"total_committers":3,"mean_commits":"16.333333333333332","dds":"0.12244897959183676","last_synced_commit":"a410d39d63087e125ec8e399cfae1500fd8d3bda"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saadmk11%2Fgithub-action-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saadmk11%2Fgithub-action-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saadmk11%2Fgithub-action-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saadmk11%2Fgithub-action-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saadmk11","download_url":"https://codeload.github.com/saadmk11/github-action-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994121,"owners_count":21030050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actions","github","github-action","github-actions","hacktoberfest","python","python-utilities","python3","python3-library","utility","utility-library","workflow","workflow-utility"],"created_at":"2024-11-09T04:45:56.981Z","updated_at":"2025-04-09T07:09:09.241Z","avatar_url":"https://github.com/saadmk11.png","language":"Python","readme":"# GitHub Action Utils\n\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/saadmk11/github-action-utils?style=flat-square)](https://github.com/saadmk11/github-action-utils/releases/latest)\n![Django Tests](https://img.shields.io/github/actions/workflow/status/saadmk11/github-action-utils/test.yaml?style=flat-square)\n![Codecov](https://img.shields.io/codecov/c/github/saadmk11/github-action-utils?style=flat-square\u0026token=ugjHXbEKib)\n[![GitHub](https://img.shields.io/github/license/saadmk11/github-action-utils?style=flat-square)](https://github.com/saadmk11/github-action-utils/blob/main/LICENSE)\n[![GitHub stars](https://img.shields.io/github/stars/saadmk11/github-action-utils?color=success\u0026style=flat-square)](https://github.com/saadmk11/github-action-utils/stargazers)\n\n![Actions Workflow Run](https://user-images.githubusercontent.com/24854406/180658147-9cfddcfe-ef51-40bc-8e0f-1949482e6a09.png)\n\n\nThis package is a collection of python functions that can be used to run [GitHub Action Workflow Commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions) from a python script inside an action workflow run.\n\n## Requirements\n\n**Python:** 3.6, 3.7, 3.8, 3.9, 3.10, 3.11\n\n## Installation\n\nInstall `github-action-utils` using pip:\n\n```console\npip install github-action-utils\n```\n## Example\n\n### Example Code\n\n```python\nimport github_action_utils as gha_utils\n\nwith gha_utils.group(\"My Group\"):\n    gha_utils.set_output(\"test_var\", \"test_value\")\n    gha_utils.save_state(\"state\", \"val\")\n\n    gha_utils.debug(\"Debug message\")\n\n    gha_utils.warning(\n        \"Warning message\", title=\"Warning Title\", file=\"example.py\",\n        col=1, end_column=2, line=5, end_line=6,\n    )\n    gha_utils.warning(\"Another warning message\")\n\n    gha_utils.error(\n        \"Error message\", title=\"Error Title\", file=\"example.py\",\n        col=1, end_column=2, line=1, end_line=2,\n    )\n    gha_utils.notice(\"Another notice message\")\n\n    gha_utils.append_job_summary(\"# Hello World\")\n    gha_utils.append_job_summary(\"- Point 1\")\n    gha_utils.append_job_summary(\"- Point 2\")\n```\n\n### Can be used inside a Workflow\n\n```yaml\nname: run-python-script\n\non:\n  pull_request:\n    branches: [ \"main\" ]\n\njobs:\n  build:\n\n    runs-on: ubuntu-latest\n\n    steps:\n    - uses: actions/checkout@v3\n\n    - name: Set up Python 3.10\n      uses: actions/setup-python@v3\n      with:\n        python-version: \"3.10\"\n\n    - name: Install dependencies\n      run: python -m pip install github-action-utils\n\n    - name: Run Python Script\n      shell: python\n      run: |\n        import github_action_utils as gha_utils\n\n        with gha_utils.group(\"My Group\"):\n            gha_utils.error(\n                \"Error message\", title=\"Error Title\", file=\"example.py\",\n                col=1, end_column=2, line=1, end_line=2,\n            )\n            gha_utils.notice(\"Another notice message\")\n            gha_utils.append_job_summary(\"# Hello World\")\n```\n\n#### Colorful Grouped Build Log Output\n![s3](https://user-images.githubusercontent.com/24854406/180003937-5839856e-09f9-47e7-8b62-f5126a78cad6.png)\n\n#### Log Annotations and Build Summery\n![s2](https://user-images.githubusercontent.com/24854406/180003153-99434824-d08c-4a54-9a89-4c6163def1b2.png)\n\n#### Log Annotations Associated with a File\n![s](https://user-images.githubusercontent.com/24854406/180003164-12735d03-a452-4bef-96a6-f1dc4298756e.png)\n\n\n## Available Functions\n\nThis section documents all the functions provided by `github-action-utils`. The functions in the package should be used inside a workflow run.\n\n**Note:** You can run the commands using python's `subprocess` module by using `use_subprocess` function parameter or `COMMANDS_USE_SUBPROCESS` environment variable.\n\n### **`echo(message, use_subprocess=False)`**\n\nPrints specified message to the action workflow console.\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import echo\n\n\u003e\u003e echo(\"Hello World\")\n\n# Output:\n# Hello World\n```\n\n### **`debug(message, use_subprocess=False)`**\n\nPrints colorful debug message to the action workflow console.\nGitHub Actions Docs: [debug](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-debug-message)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import debug\n\n\u003e\u003e debug(\"Hello World\")\n\n# Output:\n# ::debug ::Hello World\n```\n\n### **`notice(message, title=None, file=None, col=None, end_column=None, line=None, end_line=None, use_subprocess=False)`**\n\nPrints colorful notice message to the action workflow console.\nGitHub Actions Docs: [notice](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-notice-message)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import notice\n\n\u003e\u003e notice(\n    \"test message\",\n    title=\"test title\",\n    file=\"abc.py\",\n    col=1,\n    end_column=2,\n    line=4,\n    end_line=5,\n)\n\n# Output:\n# ::notice title=test title,file=abc.py,col=1,endColumn=2,line=4,endLine=5::test message=\n```\n\n### **`warning(message, title=None, file=None, col=None, end_column=None, line=None, end_line=None, use_subprocess=False)`**\n\nPrints colorful warning message to the action workflow console.\nGitHub Actions Docs: [warning](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import warning\n\n\u003e\u003e warning(\n    \"test message\",\n    title=\"test title\",\n    file=\"abc.py\",\n    col=1,\n    end_column=2,\n    line=4,\n    end_line=5,\n)\n\n# Output:\n# ::warning title=test title,file=abc.py,col=1,endColumn=2,line=4,endLine=5::test message\n```\n\n### **`error(message, title=None, file=None, col=None, end_column=None, line=None, end_line=None, use_subprocess=False)`**\n\nPrints colorful error message to the action workflow console.\nGitHub Actions Docs: [error](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-error-message)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import error\n\n\u003e\u003e error(\n    \"test message\",\n    title=\"test title\",\n    file=\"abc.py\",\n    col=1,\n    end_column=2,\n    line=4,\n    end_line=5,\n)\n\n# Output:\n# ::error title=test title,file=abc.py,col=1,endColumn=2,line=4,endLine=5::test message\n```\n\n### **`set_output(name, value)`**\n\nSets a step's output parameter by writing to `GITHUB_OUTPUT` environment file. Note that the step will need an `id` to be defined to later retrieve the output value.\nGitHub Actions Docs: [set_output](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import set_output\n\n\u003e\u003e set_output(\"my_output\", \"test value\")\n```\n\n### **`save_state(name, value)`**\n\nCreates an environment variable by writing this to the `GITHUB_STATE` environment file which is available to workflow's pre: or post: actions.\nGitHub Actions Docs: [save_state](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#sending-values-to-the-pre-and-post-actions)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import save_state\n\n\u003e\u003e save_state(\"my_state\", \"test value\")\n```\n\n### **`get_state(name)`**\n\nGets state environment variable from running workflow.\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import get_state\n\n\u003e\u003e get_state(\"test_name\")\n\n# Output:\n# test_value\n```\n\n### **`get_user_input(name)`**\n\nGets user input from running workflow.\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import get_user_input\n\n\u003e\u003e get_user_input(\"my_input\")\n\n# Output:\n# my value\n```\n\n### **`begin_stop_commands(token=None, use_subprocess=False)` and `end_stop_commands(token, use_subprocess=False)`**\n\nStops processing any workflow commands. This special command allows you to log anything without accidentally running a workflow command.\nGitHub Actions Docs: [stop_commands](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#stopping-and-starting-workflow-commands)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import echo, begin_stop_commands, end_stop_commands, stop_commands\n\n\u003e\u003e begin_stop_commands(token=\"my_token\")\n\u003e\u003e echo(\"Hello World\")\n\u003e\u003e end_stop_commands(\"my_token\")\n\n# Output:\n# ::stop-commands ::my_token\n# Hello World\n# ::my_token::\n\n# ====================\n# Using Stop Commands Context Manager\n# ====================\n\n\u003e\u003e with stop_commands(token=\"my_token\"):\n...   echo(\"Hello World\")\n\n# Output:\n# ::stop-commands ::my_token\n# Hello World\n# ::my_token::\n```\n\n### **`start_group(title, use_subprocess=False)` and `end_group(use_subprocess=False)`**\n\nCreates an expandable group in the workflow log.\nGitHub Actions Docs: [group](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import echo, start_group, end_group, group\n\n\u003e\u003e start_group(\"My Group Title\")\n\u003e\u003e echo(\"Hello World\")\n\u003e\u003e end_group()\n\n# Output:\n# ::group ::My Group Title\n# Hello World\n# ::endgroup::\n\n# ====================\n# Using Group Context Manager\n# ====================\n\n\u003e\u003e with group(\"My Group Title\"):\n...   echo(\"Hello World\")\n\n# Output:\n# ::group ::My Group Title\n# Hello World\n# ::endgroup::\n```\n\n### **`add_mask(value, use_subprocess=False)`**\n\nMasking a value prevents a string or variable from being printed in the workflow console.\nGitHub Actions Docs: [add_mask](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#masking-a-value-in-log)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import add_mask\n\n\u003e\u003e add_mask(\"test value\")\n\n# Output:\n# ::add-mask ::test value\n```\n\n### **`set_env(name, value)`**\n\nCreates an environment variable by writing this to the `GITHUB_ENV` environment file which is available to any subsequent steps in a workflow job.\nGitHub Actions Docs: [set_env](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import set_env\n\n\u003e\u003e set_env(\"my_env\", \"test value\")\n```\n\n### **`get_workflow_environment_variables()`**\n\nGets all environment variables from the `GITHUB_ENV` environment file which is available to the workflow.\nGitHub Actions Docs: [set_env](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import get_workflow_environment_variables\n\n\u003e\u003e get_workflow_environment_variables()\n\n# Output:\n# {\"my_env\": \"test value\"}\n```\n\n### **`get_env(name)`**\n\nGets all environment variables from `os.environ` or the `GITHUB_ENV` environment file which is available to the workflow.\nThis can also be used to get [environment variables set by GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables).\nGitHub Actions Docs: [set_env](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import get_env\n\n\u003e\u003e get_env(\"my_env\")\n\u003e\u003e get_env(\"GITHUB_API_URL\")\n\n# Output:\n# test value\n# https://api.github.com\n```\n\n### **`append_job_summary(markdown_text)`**\n\nSets some custom Markdown for each job so that it will be displayed on the summary page of a workflow run.\nGitHub Actions Docs: [append_job_summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import append_job_summary\n\n\u003e\u003e append_job_summary(\"# test summary\")\n```\n\n\n### **`overwrite_job_summary(markdown_text)`**\n\nClears all content for the current step, and adds new job summary.\nGitHub Actions Docs: [overwrite_job_summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#overwriting-job-summaries)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import overwrite_job_summary\n\n\u003e\u003e overwrite_job_summary(\"# test summary\")\n```\n\n### **`remove_job_summary()`**\n\ncompletely removes job summary for the current step.\nGitHub Actions Docs: [remove_job_summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#removing-job-summaries)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import remove_job_summary\n\n\u003e\u003e remove_job_summary()\n```\n\n### **`add_system_path(path)`**\n\nPrepends a directory to the system PATH variable (`GITHUB_PATH`) and automatically makes it available to all subsequent actions in the current job.\nGitHub Actions Docs: [add_system_path](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import add_system_path\n\n\u003e\u003e add_system_path(\"var/path/to/file\")\n```\n\n### **`event_payload()`**\n\nGet GitHub Event payload that triggered the workflow.\n\nMore details: [GitHub Actions Event Payload](https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads)\n\n**example:**\n\n```python\n\u003e\u003e from github_action_utils import event_payload\n\n\u003e\u003e event_payload()\n\n# Output:\n# {\"action\": \"opened\", \"number\": 1, \"pull_request\": {\"url\": \"https://api.github.com/repos/octocat/Hello-World/pulls/1\"}, \"repository\": {\"url\": \"https://api.github.com/repos/octocat/Hello-World\"}, \"sender\": {\"login\": \"octocat\"}...}\n```\n\n# License\n\nThe code in this project is released under the [MIT License](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaadmk11%2Fgithub-action-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaadmk11%2Fgithub-action-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaadmk11%2Fgithub-action-utils/lists"}