book/tools/scripts/docs/WORKFLOW_CLEANUP.md
This script helps clean up old GitHub workflow runs while keeping a configurable number of recent runs per workflow. It's particularly useful when you have many failed runs from debugging.
Get a GitHub Personal Access Token
actions:write and repo scopesSet up the token
# Option 1: Set environment variable (recommended)
export GITHUB_TOKEN="your_token_here"
# Option 2: Use --token flag each time
Preview what would be cleaned up
python3 tools/scripts/cleanup_workflow_runs.py --summary
python3 tools/scripts/cleanup_workflow_runs.py --dry-run --keep 5
Actually clean up workflow runs
# Keep 5 most recent runs per workflow
python3 tools/scripts/cleanup_workflow_runs.py --keep 5
# Keep 10 most recent runs per workflow
python3 tools/scripts/cleanup_workflow_runs.py --keep 10
# See summary of all workflows and run counts
python3 tools/scripts/cleanup_workflow_runs.py --summary
# See what would be deleted (keeping 5 runs per workflow)
python3 tools/scripts/cleanup_workflow_runs.py --dry-run --keep 5
# Preview cleanup for specific workflow
python3 tools/scripts/cleanup_workflow_runs.py --dry-run --workflow "quarto-build-container.yml" --keep 3
# Clean all workflows, keep 5 most recent runs each
python3 tools/scripts/cleanup_workflow_runs.py --keep 5
# Clean specific workflow only, keep 3 runs
python3 tools/scripts/cleanup_workflow_runs.py --workflow "quarto-build-container.yml" --keep 3
# Keep more runs (10 per workflow)
python3 tools/scripts/cleanup_workflow_runs.py --keep 10
# Set token once
export GITHUB_TOKEN="ghp_your_token_here"
# Override repository detection
export GITHUB_REPOSITORY="owner/repo"
You can target specific workflows by name or filename:
# By workflow filename
python3 tools/scripts/cleanup_workflow_runs.py --workflow "quarto-build-container.yml" --keep 3
# By workflow name
python3 tools/scripts/cleanup_workflow_runs.py --workflow "Quarto Build" --keep 3
❌ Permission denied. Check your token has 'actions:write' scope.
actions:write and repo scopes⚠️ Rate limit exceeded. Waiting 60 seconds...
❌ Repository not specified and could not auto-detect from git
--repo owner/repo flag| Option | Default | Description |
|---|---|---|
--keep | 5 | Number of recent runs to keep per workflow |
--workflow | (all) | Target specific workflow by name or filename |
--dry-run | false | Preview mode - don't actually delete |
--summary | false | Show workflow summary and exit |
--token | env var | GitHub personal access token |
--repo | auto-detect | Repository in owner/repo format |
--dry-run to preview changes--workflow for problematic workflows