GitHub Action
Clean workflow runs
Flexible and configurable action for removing completed workflow runs.
Alternative actions have many restrictions, and it is unusable in some cases.
A personal access token.
Default: context variable github.token
. See restriction of the variable github.token
on official page..
A repository from which delete workflow runs. Default is current repository.
Format of field: {owner}/{repo_name}
.
Default: current repository.
A filename of workflow or its id. By default, the action grabs all workflows.
Default: action deletes runs of all workflows.
A branch from which delete workflow runs. Default is all branches.
Default: action deletes runs from all branches.
Filter for workflow runs conclusion. Accepts all available conclusions..
Format of field:
- a multiline string:
run_conclusions: |
conclusion1
conclusion2
- a comma separated string:
run_conclusions: conclusion1,conclusion2
Attention. Do not mix the formats of conclusions.
Default: action grabs all run conclusions.
Note. If filter has invalid conclusions, it will be ignored. If filter contains only invalid conclusions, then no workflow runs will be deleted.
Determines period during which the workflow runs will be saved.
Format of field:
- a number of days:
save_period: 10
- a string in format
hh:mm:ss
:
save_period: '36:00:00'
Default: 90 days.
A minimal number of completed runs which will be saved.
Default: 10 runs.
Note: : this filter applies to the conclusions selected by options run_conclusions
. If you need to delete all filtered workflow runs, setup the option to 0
.
Enables dry run of action. Action will print the list of workflow runs to delete.
Default: false.
The option can help to debug the workflow.
- name: Delete workflow runs
uses: dmvict/[email protected]
with:
token: ${{ secrets.PRIVATE_GITHUB_TOKEN }}
repo: user/repo
workflow_id: TheWorkflow.yml
branch: main
run_conclusions: |
failure
timed_out
save_period: 30
save_min_runs_number: 1
dry: true
It reads: clean all all runs of the workflow TheWorkflow.yml
in repository repo
of user user
, runs should be older than 30 days, delete runs on branch main
with status failure
or timed_out
. Option save_min_runs_number
says that at least single run with statuses failure
or timed_out
will be saved.
Option dry
is true
, so action deletes no workflow runs and print list of runs which should be deleted.
All defaults: delete all runs older than 90 days, save at least 10 runs.
jobs:
delete_runs:
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: dmvict/[email protected]
Filter by conclusion and save no runs older than 6 hours.
jobs:
delete_runs:
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: dmvict/[email protected]
with:
token: ${{ secrets.PRIVATE_GITHUB_TOKEN }}
run_conclusions: |
cancelled
skipped
save_period: '06:00:00'
save_min_runs_number: 0
It is useful if you need to save runs on some branch ( for example, branch for production releases ).
The workflow will delete failed runs older than 10 days in branches dev
and staging
.
jobs:
delete_runs:
strategy :
matrix :
branch :
- dev
- staging
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: dmvict/[email protected]
with:
token: ${{ secrets.PRIVATE_GITHUB_TOKEN }}
run_conclusions: |
failure
branch: ${{ matrix.branch }}
save_period: 10
If you want to use single workflow to clean several repositories. Default token github.token
can have no access to another repositories. It is better to use generated personal access token.
jobs:
delete_runs:
strategy :
matrix :
repository :
- user/repo-dev
- user/repo-prod
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: dmvict/[email protected]
with:
token: ${{ secrets.PRIVATE_GITHUB_TOKEN }}
repo: ${{ matrix.repository }}
save_period: 120
The action makes many API calls - at least 1 per 100 workflow runs + at least 1 per deleted workflow run.
Example: repository has 3000 workflow runs and all should be deleted:
3000/100 + 3000 = 3030;
For example above, at least 3030
API requests will be consumed.
Please, use action taking into account the information above.