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.
Currently, GitHub does not provide built-in Retention policy for workflow runs.
As the workaround, you can try like as this:
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).
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
You may have to run it a few times, due to pagination.