Created
January 12, 2022 10:34
-
-
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
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
# ====================================================================================== | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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