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/
    python3 -m build
    pip3 install dist/gh_prune-*.whl --force-reinstall
    

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.1.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.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gh_prune-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 eb2833b36ffc5b82ed32de83d1bad7c6d6e8993574301a43c1a2756e1f171de0
MD5 140e91b64a12b8f06b4d894bc6484488
BLAKE2b-256 845d71b62b523661b4c56e66cbef03a301ad119971372079a246ee9578281c73

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gh_prune-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 023dcceb6b56a5b48c50d6f718a1a3164df0c1dac1d0b86c86e58a596f9b4da2
MD5 77758878eae542a97f69d4ab266ef35b
BLAKE2b-256 7b1facdfdc1df355755f20e50a9085627d7b75578a1e8d7adb1566a24c58c7af

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