Skip to content

Instantly share code, notes, and snippets.

@MrChocolatine
Last active December 3, 2022 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrChocolatine/3245610495df711b266fc4237a0e1529 to your computer and use it in GitHub Desktop.
Save MrChocolatine/3245610495df711b266fc4237a0e1529 to your computer and use it in GitHub Desktop.
GitHub - How to delete all workflow runs

While GitHub provides the ability to remove old workflow runs (https://github.blog/changelog/2020-07-07-github-actions-ability-to-delete-workflow-runs/), it fails to provide an option to delete all workflow runs for a particular workflow.

Manual deletion can become extremely tedious...

Turns out, this can be achieved using GitHub CLI (https://github.com/cli/cli), read on.

  • Idea initially noticed here: refined-github/refined-github#4838

  • Which brought me here: cli/cli#6449 where this solution in given:

    gh run \
      list --json databaseId  -q '.[].databaseId' -w integration.yml --limit 500 \
      | xargs -IID -P 15 \
        gh api "repos/$(gh repo view --json nameWithOwner -q .nameWithOwner)/actions/runs/ID" \
        -X DELETE
    
@MrChocolatine
Copy link
Author

For posterity, here is the original message (the solution) posted by @fregante :

@alef that works but it's excruciatingly slow on my end 😬 like 30 seconds per 20 deletions.
Adding -P 8 to xargs considerably sped it up!

Here's the full command I'm using to delete:

  • only integration.yml
  • up to 500 at per run
  • up to 15 parallel requests
gh run list --json databaseId  -q '.[].databaseId' -w integration.yml --limit 500 |
        xargs -IID -P 15 gh api \
              "repos/$(gh repo view --json nameWithOwner -q .nameWithOwner)/actions/runs/ID" \
              -X DELETE

This only took 50 seconds per 500 deletions, which is much more reasonable. I deleted 1700 runs in
a few runs, but I reached the API limit so I had to stop it and wait a few more seconds 👍

@fregante
Copy link

fregante commented Dec 3, 2022

I am @fregante and I approve this message 😂

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