Created
September 15, 2024 20:31
-
-
Save josephgoksu/be8283b604e36c86af9e3be24b90075a to your computer and use it in GitHub Desktop.
This file contains 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 | |
set -x | |
# Set the GitHub repository name | |
repo="username/reponame" | |
# Function to delete a single run | |
delete_run() { | |
local run_id=$1 | |
if [[ "$run_id" =~ ^[0-9]+$ ]]; then | |
if gh run delete "$run_id" -R "$repo"; then | |
echo "Successfully deleted run $run_id" | |
else | |
echo "Failed to delete run $run_id" | |
fi | |
else | |
echo "Invalid run ID: $run_id" | |
fi | |
} | |
# List and delete all workflow runs | |
echo "Listing and deleting workflow runs..." | |
gh run list -R "$repo" --limit 1000 | while read -r line; do | |
run_id=$(echo "$line" | awk '{print $(NF-2)}') | |
delete_run "$run_id" | |
done | |
echo "Finished attempting to delete workflow runs." | |
# Verify deletion by listing runs again | |
echo "Verifying deletion..." | |
remaining_runs=$(gh run list -R "$repo" --limit 10) | |
if [ -z "$remaining_runs" ]; then | |
echo "All workflow runs have been successfully deleted." | |
else | |
echo "Some workflow runs still remain:" | |
echo "$remaining_runs" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment