Last active
November 13, 2021 03:30
-
-
Save paulocoutinhox/dc6e4bb77ae05693e53c5d4552dd3981 to your computer and use it in GitHub Desktop.
Delete All Github Runs From 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
# Requirements: Github Client (gh) and JQ tool (jq) | |
# 1 - Change: OWNER, REPO | |
# 2 - Execute one time to get all workflows IDs | |
# 3 - Change: WORKFLOW_ID | |
OWNER=<your user/org name> | |
REPO=<repo name> | |
# list workflows | |
gh api -X GET /repos/$OWNER/$REPO/actions/workflows | jq '.workflows[] | .name,.id' | |
# copy the ID of the workflow you want to clear and set it | |
WORKFLOW_ID=<workflow id> | |
# list runs | |
gh api -X GET /repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_ID/runs | jq '.workflow_runs[] | .id' | |
# delete runs (you'll have to run this multiple times if there's many because of pagination) | |
gh api -X GET /repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_ID/runs | jq '.workflow_runs[] | .id' | xargs -I{} gh api -X DELETE /repos/$OWNER/$REPO/actions/runs/{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment