Created
April 29, 2025 20:39
-
-
Save shrugs/4cb24eafecc8a3f2c5b45ba4f882ac45 to your computer and use it in GitHub Desktop.
delete old workflow file runs
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 | |
set -e | |
# Script to delete GitHub Actions workflow runs for a repository | |
# Requirements: GitHub CLI (gh) and jq must be installed | |
# You must be authenticated with gh cli before running this script | |
# Repository information | |
REPO_OWNER="OWNER" | |
REPO_NAME="REPO" | |
# Optional workflow name filter | |
WORKFLOW_PATH=".github/workflows/WORKFLOW_PATH_CHANGE_ME.yml" | |
echo "Fetching workflow runs from GitHub..." | |
temp_file="workflow_runs.json" | |
# Get all workflow runs and save to temporary file | |
gh api "/repos/${REPO_OWNER}/${REPO_NAME}/actions/runs" --paginate > "$temp_file" | |
# Extract workflow run IDs and delete each one | |
jq_filter=".workflow_runs[] | select(.path == \"$WORKFLOW_PATH\") | .id" | |
echo "Deleting workflow runs..." | |
for run_id in $(cat "$temp_file" | jq -r "$jq_filter"); do | |
echo "Deleting workflow run ID: $run_id" | |
gh api -X DELETE "/repos/${REPO_OWNER}/${REPO_NAME}/actions/runs/$run_id" --silent | |
# Small delay to avoid rate limiting | |
sleep 0.5 | |
done | |
# Clean up | |
rm -f "$temp_file" | |
echo "All workflow runs have been deleted successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment