Skip to content

Instantly share code, notes, and snippets.

@iamludal
Created December 24, 2023 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamludal/24902361ecc17053597023281a623a39 to your computer and use it in GitHub Desktop.
Save iamludal/24902361ecc17053597023281a623a39 to your computer and use it in GitHub Desktop.
Delete all GitHub workflow runs for a given workflow
#!/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