A GitHub Action to clean up old workflow runs and save storage space in your repository.
- Clean workflow runs older than a specified number of days
- Keep a specified number of latest runs per workflow
- Support for dry run mode to preview what would be deleted
- Handles orphaned workflow runs
- Provides detailed output statistics
name: Clean Workflow Runs
on:
schedule:
- cron: "0 16 * * 1" # Weekly cleanup
workflow_dispatch:
jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
actions: write
contents: read
steps:
- name: Clean old workflow runs
uses: diverger/gh-clean-workflow
with:
runs_older_than: "30"
runs_to_keep: "5"
dry_run: "false"
Input | Description | Default | Required |
---|---|---|---|
runs_older_than |
Number of days old to delete | 21 |
No |
runs_to_keep |
Number of latest runs to keep per workflow | 0 |
No |
dry_run |
Only show what would be deleted | true |
No |
github_token |
GitHub token with actions:write permissions | ${{ github.token }} |
No |
Note
The dry_run
parameter defaults to true
. So by default it will delete nothing and you can preview in the log output to see what would be deleted.
Tip
For regular maintenance, consider setting runs_older_than
to 30+ days and runs_to_keep
to 5-10 runs per workflow.
Important
This action requires actions: write
permissions to delete workflow runs.
Warning
Deleted workflow runs cannot be recovered. Always test with dry_run: true
first.
Caution
Be careful when setting runs_to_keep
to 0, as this will delete all runs older than the specified days.
Output | Description |
---|---|
total_runs |
Total number of workflow runs found |
deleted_runs |
Number of workflow runs deleted |
kept_runs |
Number of workflow runs kept |
The action requires the following permissions:
permissions:
actions: write
contents: read
MIT