Skip to content

Instantly share code, notes, and snippets.

@gearsandcode
Created February 15, 2025 07:28
Show Gist options
  • Save gearsandcode/b48993a8ffa1221b69536afa1f36d96c to your computer and use it in GitHub Desktop.
Save gearsandcode/b48993a8ffa1221b69536afa1f36d96c to your computer and use it in GitHub Desktop.
Batch delete GitHub Action runs

Delete GitHub Workflow Runs

This command will batch delete all workflow runs in your repository.

Install GitHub CLI

For Mac OSX, use Brew

brew install gh

Authenticate

gh auth login

Add script to .zshenv

cat << 'EOF' >> ~/.zshenv

function gh_bulk_delete_workflow_runs() {
  repo=$1

  # Ensure the repo argument is provided
  if [[ -z "$repo" ]]; then
    echo "Usage: gh_bulk_delete_workflow_runs <owner/repo>"
    return 1
  fi

  # Fetch all workflow runs for the given repository 
  runs=$(gh api repos/$repo/actions/runs --paginate | jq -r '.workflow_runs[] | .id')

  while IFS= read -r run; do
    echo "Deleting run $run..."
    gh api -X DELETE repos/$repo/actions/runs/$run --silent
  done <<< "$runs"

  echo "All workflow runs for $repo have been deleted."
}
EOF

Source .zshenv

source ~/.zshenv

Run function

Replacing the owner/repo with your repo

gh_bulk_delete_workflow_runs owner/repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment