Skip to content

Instantly share code, notes, and snippets.

@rameezk
Created March 18, 2025 07:32
Show Gist options
  • Select an option

  • Save rameezk/941c39e7696c7c9d079bb79e160f836b to your computer and use it in GitHub Desktop.

Select an option

Save rameezk/941c39e7696c7c9d079bb79e160f836b to your computer and use it in GitHub Desktop.
Delete all GitHub workflow runs using the gh cli
#!/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