Skip to content

Instantly share code, notes, and snippets.

@xfathurrahman
Last active January 12, 2025 13:49
Show Gist options
  • Save xfathurrahman/2bd412997e19b18cedd89b3d3aa6ac32 to your computer and use it in GitHub Desktop.
Save xfathurrahman/2bd412997e19b18cedd89b3d3aa6ac32 to your computer and use it in GitHub Desktop.
Delete All GitHub Workflow Runs Script
#!/bin/bash
# Replace with your personal access token
GITHUB_TOKEN="your-personal-access-token"
# Replace with the repository owner's name
OWNER="your-username"
# Replace with the repository name
REPO="your-repo-name"
# Get the list of workflow runs
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$OWNER/$REPO/actions/runs")
# Check if the response is not null
if [ -z "$response" ]; then
echo "Failed to retrieve workflow runs. Please check your network connection and GitHub token."
exit 1
fi
workflow_runs=$(echo "$response" | jq -r '.workflow_runs[].id')
# Check if workflow_runs is not null
if [ -z "$workflow_runs" ]; then
echo "No workflow runs found."
exit 0
fi
# Delete each workflow run
for run_id in $workflow_runs; do
echo "Deleting workflow run ID: $run_id"
curl -s -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/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