Feature: Delete *all* old workflow runs

I have currently over 300 workflow runs cluttering my github actions. Mainly old workflows that are not used anymore for months. Is there any way to delete them all together? I could only find a one by one delete option.


@valentijnscholten ,

Currently, GitHub does not provide built-in Retention policy for workflow runs.

As the workaround, you can try like as this:

  1. Set up a workflow runs on schedule event and/or workflow_dispatch event.

  2. Set up a step in the workflow to execute the “List workflow runs for a repository” API. This API will return the details of all the workflow runs in the repository. From the retuned details, you can get the time when each run was triggered ( created_at).

  3. Calculate the time interval between the created_at of each run and current time. If the interval between reaches 1 month (30 days), use the “Delete a workflow run” API to delete the run.

Of course, if you really need the feature that GitHub provides built-in Retention policy for workflow runs, I recommend that you can directly report a feature request here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

@valentijnscholten did you end up filing a feature request for this? I would heavily +1 a request for adding this to the GH Actions UI.

You can do so using the GitHub API. Here’s a Python script:

from ghapi.all import GhApi
api = GhApi()

owner = '<github username>'
repo = '<repo name>'

runs = api.actions.list_workflow_runs_for_repo(owner, repo)
for run in runs.workflow_runs:
    api.actions.delete_workflow_run(owner, repo, run.id)

The script uses the ghapi python package, and relies on a GITHUB_TOKEN environment variable; see the ghapi docs.

You may have to run it a few times, due to pagination.

1 Like

Heavily +1 I’m about to do some manual scripting to delete old cruft workflows. Would prefer to be able to do this simply in the UI. I would prefer to choose an “Workflow” name on the left pane in Actions screen, and then delete all of that workflow type. I’ve attached an image explaining…