Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vispercept/2904a01e1455be289c3c1b4ea0e06bdd to your computer and use it in GitHub Desktop.
Save Vispercept/2904a01e1455be289c3c1b4ea0e06bdd to your computer and use it in GitHub Desktop.
Delete all github-workflow runs of a given workflow_id to cleanup the actions-section
# ======================================================================================
# Delete all github-workflow runs of a given workflow_id to cleanup the actions-section
#
# original gist:
# https://gist.github.com/zulhfreelancer/a32bee3d37ffb90c93e00bf4b7fe26cf
#
# Requirements
# * gh CLI: https://cli.github.com (make sure you are logged-in to the CLI)
# * jq CLI: https://stedolan.github.io/jq
# ======================================================================================
export TARGET_USER=<__>
export TARGET_REPO=<__>
export TARGET_WORKFLOW_ID=<__>
while :
do
SIZE=$(gh api repos/$TARGET_USER/$TARGET_REPO/actions/workflows/$TARGET_WORKFLOW_ID/runs | jq -r .total_count)
echo "Found: $SIZE"
if [[ $SIZE -eq 0 ]]
then
echo "All done"
break
fi
gh api repos/$TARGET_USER/$TARGET_REPO/actions/workflows/$TARGET_WORKFLOW_ID/runs | \
jq -r '.workflow_runs[] | .id' | \
xargs -n1 -I % gh api --silent repos/$TARGET_USER/$TARGET_REPO/actions/runs/% -X DELETE
sleep 1
done
@linhandev
Copy link

linhandev commented Jan 11, 2023

This works for records of workflows whose workflow file has already been deleted.

TARGET_WORKFLOW_ID is just the filename for the workflow xx.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment