Created
April 8, 2022 10:00
-
-
Save Jolg42/7b84a5fb53b8dff6dfe0cb434cad3f54 to your computer and use it in GitHub Desktop.
Script to delete GitHub Actions worfklow runs for cleanup (only way to get rid of an unused workflow, is to delete all the runs)
This file contains 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
OWNER=prisma | |
REPO=the-repo | |
# 1. list workflows | |
gh api -X GET /repos/$OWNER/$REPO/actions/workflows | jq '.workflows[] | .name,.id' | |
# 2. copy the ID of the workflow you want to clear and set it | |
WORKFLOW_ID=ID-FROM-PREVIOUS-STEP | |
# 3. list runs as safe check before deting | |
# gh api --field per_page=100 -X GET /repos/$OWNER/$REPO/actions/workflows/$WORKFLOW_ID/runs | jq '.workflow_runs[] | .id' | |
# 4. delete runs (you'll have to run this multiple times if there's many because of pagination) | |
# gh api --paginate -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/{} | |
# # repeat command X times, 100 results at a time | |
# for i in {1..200}; do gh api --field per_page=100 -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/{}; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment