Skip to content

Instantly share code, notes, and snippets.

@paulocoutinhox
Last active November 13, 2021 03:30
Show Gist options
  • Save paulocoutinhox/dc6e4bb77ae05693e53c5d4552dd3981 to your computer and use it in GitHub Desktop.
Save paulocoutinhox/dc6e4bb77ae05693e53c5d4552dd3981 to your computer and use it in GitHub Desktop.
Delete All Github Runs From Workflow
# 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