Created
December 24, 2023 16:15
-
-
Save iamludal/24902361ecc17053597023281a623a39 to your computer and use it in GitHub Desktop.
Delete all GitHub workflow runs for a given workflow
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 | |
workflow=$1 | |
limit=$2 | |
if [[ -z "$workflow" ]] | |
then | |
echo "Usage: $0 <workflow> [<limit>]" | |
exit 1 | |
fi | |
if [[ ! -z "$limit" ]] | |
then | |
args="-L $limit" | |
else | |
args='' | |
fi | |
workflow_runs=$(gh run list -w "$workflow" --json databaseId $args | jq '.[].databaseId') | |
run_count=$(echo "$workflow_runs" | wc -l | tr -d ' ') | |
echo "$run_count runs to delete" | |
for run_id in $workflow_runs | |
do | |
gh run delete "$run_id" | |
echo "Run $run_id: deleted successfully" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment