Skip to main content

CLI to prune GitHub workflow runs

Project description

License Open Source Love MIT License Maintained GitHub last commit Python PRs Welcome

gh-prune

gh-prune is a command-line utility designed to help you manage and prune GitHub Actions workflow runs efficiently. It interacts with the GitHub CLI (gh) to list, inspect, and delete workflow runs, helping you maintain a clean repository and manage usage limits.

Prerequisites

Before using gh-prune, ensure you have the following installed:

  1. Python 3.x
  2. GitHub CLI (gh):
  3. Python Dependencies:
    • typer
    • rich

Installation

  1. Clone the repository:

    git clone https://github.com/ifaakash/gh-prune.git
    cd gh-prune
    
  2. Install dependencies:

    pip install typer rich
    
  3. Authenticate with GitHub:

    gh auth login --hostname github.com
    

Build and Run Locally

To build and run the project locally, it is highly recommended to use a separate virtual environment (venv).

  1. Create and Activate Virtual Environment:

    python3 -m venv venv
    source venv/bin/activate
    
  2. Build and Install:

    rm -rf dist/ build/ *.egg-info
    python3 -m build
    pip3 uninstall gh-prune -y
    pip3 install dist/gh_prune-*.whl --force-reinstall
    twine check dist/*
    twine upload dist/*
    

Usage

The tool is executed via doctor.py. Below are the available commands.

1. Health Check (doctor)

Verifies that the GitHub CLI is installed and correctly authenticated.

python3 doctor.py doctor

2. List Workflows (workflow-list)

Lists all workflows in a specified repository, showing their names, IDs, and states.

Syntax:

python3 doctor.py workflow-list [OWNER/REPO]

Example:

python3 doctor.py workflow-list ifaakash/gh-prune

3. List Workflow Runs (workflow-run-list)

Lists the recent runs of a specific workflow file.

Syntax:

python3 doctor.py workflow-run-list [OWNER/REPO] [WORKFLOW_FILENAME]

Example:

python3 doctor.py workflow-run-list ifaakash/gh-prune pylint.yml

4. Delete Old Runs (workflow-run-delete)

Deletes old workflow runs but keeps a specified number of the most recent ones. Useful for cleaning up history while retaining the latest status.

Syntax:

python3 doctor.py workflow-run-delete [OWNER/REPO] [WORKFLOW_FILENAME] --keep [N] --limit [M]

Options:

  • --keep: Number of recent runs to keep (default: 5).
  • --limit: Number of runs to fetch for processing (default: 30).
  • --yes / -y: Skip confirmation prompt.

Example:

python3 doctor.py workflow-run-delete ifaakash/news-agent cron-workflow.yml --keep 180 --limit 200

5. Prune All Runs (workflow-run-prune)

Deleting ALL runs for a specific workflow up to a specified limit. Use with caution.

Syntax:

python3 doctor.py workflow-run-prune [OWNER/REPO] [WORKFLOW_FILENAME] --limit [M]

Options:

  • --limit: Number of runs to fetch and delete (default: 30).
  • --yes / -y: Skip confirmation prompt.

Example:

python3 doctor.py workflow-run-prune ifaakash/news-agent cron-workflow.yml --limit 200

Help

To see a tabular summary of commands and examples directly in the terminal, run:

python3 doctor.py docs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gh_prune-0.1.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gh_prune-0.1.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file gh_prune-0.1.2.tar.gz.

File metadata

  • Download URL: gh_prune-0.1.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for gh_prune-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c0a986f91679016de73d54ec4e1cf811f56fb3f40adcfe29fe96d51265018019
MD5 8c4baf0aec48505a18c15069fcc06b94
BLAKE2b-256 196deb764b24a6ea4e000ba9eaf28203bc5502836e482a29bac6795f23424c52

See more details on using hashes here.

File details

Details for the file gh_prune-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: gh_prune-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for gh_prune-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 cf136fe28bf3d6dfff088f989ad15418cdb73096c845bfb5a96085e82a706b7d
MD5 4e1d5b806d08f2de9eda6aba5813b170
BLAKE2b-256 a3d653c961843e5c5c56aa9ab779c6e3421d41d47ca58749d62caa4e4ce645e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page