Created
March 18, 2025 07:32
-
-
Save rameezk/941c39e7696c7c9d079bb79e160f836b to your computer and use it in GitHub Desktop.
Delete all GitHub workflow runs using the gh cli
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
| #!/usr/bin/env bash | |
| org=<gh-org> | |
| repo=<gh-repo> | |
| workflow_name=<gh-workflow-name> | |
| workflow_ids=$(gh api repos/$org/$repo/actions/workflows --paginate | jq --arg name "$workflow_name" '.workflows[] | select(.["name"] | contains($name)) | .id') | |
| for workflow_id in $workflow_ids; | |
| do | |
| echo "Listing runs for the workflow ID $workflow_id" | |
| run_ids=$(gh api repos/$org/$repo/actions/workflows/$workflow_id/runs --paginate | jq '.workflow_runs[].id') | |
| echo "$run_ids" | |
| for run_id in $run_ids; | |
| do | |
| echo "Deleting Run ID $run_id" | |
| gh api -X DELETE "repos/$org/$repo/actions/runs/$run_id" | |
| done | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment