Skip to content

Instantly share code, notes, and snippets.

@bruceharrison1984
Created July 13, 2021 16:25
Show Gist options
  • Save bruceharrison1984/18d6c27b614a29d40b90eb9c741cac37 to your computer and use it in GitHub Desktop.
Save bruceharrison1984/18d6c27b614a29d40b90eb9c741cac37 to your computer and use it in GitHub Desktop.
Delete Github Action Workflow Runs
### Stolen from https://stackoverflow.com/a/67000032
### Run multiple times, or use in a loop
org=<ORG>
repo=<REPO>
# Get workflow IDs with status "disabled_manually"
workflow_ids=($(gh api repos/$org/$repo/actions/workflows | jq '.workflows[] | select(.["state"] | contains("disabled_manually")) | .id'))
for workflow_id in "${workflow_ids[@]}"
do
echo "Listing runs for the workflow ID $workflow_id"
run_ids=($(gh api repos/$org/$repo/actions/workflows/$workflow_id/runs | jq -r '.workflow_runs[].id'))
for run_id in "${run_ids[@]/$'\r'}"
do
echo $run_id
echo "Deleting Run ID $run_id"
gh api repos/$org/$repo/actions/runs/$run_id -X DELETE >/dev/null
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment