Skip to content

Instantly share code, notes, and snippets.

@lazuee
Created October 4, 2023 02:25
Show Gist options
  • Save lazuee/366385f8a97a725c661ca74fc2820430 to your computer and use it in GitHub Desktop.
Save lazuee/366385f8a97a725c661ca74fc2820430 to your computer and use it in GitHub Desktop.
Delete workflow runs
#!/bin/bash
repo="lazuee/lazuee"
url="repos/$repo/actions/runs"
total_deleted=0
delete_id() {
local id=$1
local result=""
if gh api -X DELETE "$url/$id" --silent; then
result="✅: Deleted '$id'"
total_deleted=$((total_deleted+1))
else
result="❌: Failed '$id'"
echo "An error occurred while deleting ID '$id'. Press Enter to exit."
echo "Total IDs deleted: $total_deleted"
read -n 1 -s -r -p ""
exit 1
fi
printf "%s\n" "$result"
}
while true; do
total_ids=$(gh api "$url" | jq '.workflow_runs | length')
if [[ $total_ids -eq 0 ]]; then
echo "No more IDs to delete. Press Enter to exit."
echo "Total IDs deleted: $total_deleted"
read -n 1 -s -r -p ""
break
fi
gh api "$url" |
jq '.workflow_runs[].id' |
while read -r id; do
id="${id//$'\r'/}"
delete_id "$id"
done
sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment