Created
July 25, 2025 13:11
-
-
Save spdeepak/6a7a642fb00ea9fd6d2345ce8a446018 to your computer and use it in GitHub Desktop.
Delete github workflows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| OWNER="$1" | |
| REPO="$2" | |
| if [[ -z "$OWNER" || -z "$REPO" ]]; then | |
| echo "Usage: ./run.sh <GitHub-Owner> <GitHub-Repo>" | |
| exit 1 | |
| fi | |
| if ! command -v gh &> /dev/null; then | |
| echo "❌ GitHub CLI (gh) is not installed" | |
| exit 1 | |
| fi | |
| # Disable paging explicitly | |
| export GH_PAGER= | |
| echo "🔍 Fetching workflow run IDs for $OWNER/$REPO..." | |
| workflow_runs=$(gh api "repos/$OWNER/$REPO/actions/runs" --paginate -q '.workflow_runs[].id') | |
| if [[ -z "$workflow_runs" ]]; then | |
| echo "ℹ️ No workflow runs found for $OWNER/$REPO." | |
| exit 0 | |
| fi | |
| # Loop and delete each run | |
| echo "$workflow_runs" | while read -r run_id; do | |
| echo "🗑️ Deleting workflow run ID: $run_id" | |
| gh api -X DELETE "repos/$OWNER/$REPO/actions/runs/$run_id" | |
| done | |
| echo "✅ All workflow runs have been deleted." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment