This GH action removes action runs from a repository. By default, obsolete workflow runs are deleted. Additional filter can be applied to deleted workflow runs by status/conclusion - see input parameters below for details.
Name | Description | Default | Is optional |
---|---|---|---|
token |
The token used to authenticate | ${{ github.token }} |
true |
remove-obsolete |
Remove obsolete workflows | true |
true |
remove-cancelled |
Remove cancelled workflows | false |
true |
remove-failed |
Remove failed workflows | false |
true |
remove-older-than |
Remove workflows older than timeframe | <null> |
true |
remove-skipped |
Remove skipped workflows | false |
true |
Warning
In the next major version the default of remove-obsolete
will change from true
to false
!
All inputs are optional - if any input is not given, the default value will be used.
-
token
-
- Using
github.token
usually works, unless the actions are not scoped withrepo
rights. For more details, see theGITHUB_TOKEN
. - If the workflow has issues, you may need to use a personal access token (PAT) that must have the
repo
scope. More details, see "Creating a personal access token".
- Using
-
remove-obsolete
-
- All workflows that don't have a matching definition anymore will be deleted
-
remove-cancelled
-
- Remove workflows from the list that have been cancelled earlier
- Accepts either a boolean or a multiline
string
. Each line will be matched against the workflow'sname
. On match the run will be removed.
-
remove-failed
-
- Remove workflows from the list that have failed earlier
- Accepts either a boolean or a multiline
string
. Each line will be matched against the workflow'sname
. On match the run will be removed.
-
remove-older-than
-
- Remove workflows from the list that are older than the given timeframe (e.g. '10s', '30m', '12h', '7d', '2w', '6y' or any combination of these).
- Accepts a (multiline)
string
in the format ofNU [W]
whereN
is a number,U
is a time unit and optionallyW
is the workflow name. The following units are supported:s
for secondsm
for minutesh
for hoursd
for daysw
for weeksy
for years
- When given as a multiline string, each line will be parsed as a separate input
- When given with
W = *
or without a workflow name, all workflows will be checked - When given with a workflow name, only the matching workflows will be checked
-
remove-skipped
-
- Remove workflows from the list that have been skipped earlier
- Accepts either a boolean or a multiline
string
. Each line will be matched against the workflow'sname
. On match the run will be removed.
Important
All given inputs are applied (i.e. combined with a logical OR
).
name: Scheduled purge of failed workflow runs
on:
schedule:
- cron: '54 0 * * 0'
jobs:
purge_obsolete_workflows:
runs-on: ubuntu-latest
steps:
- uses: otto-de/purge-deprecated-workflow-runs@v2
with:
remove-obsolete: false
remove-failed: true
The example below will trigger a run of this workflow each time a deployment status changes.
All runs until success
will be skipped and then cleaned up in the success
case:
name: Manage Deployments
on:
deployment_status:
jobs:
clean_unfinished_deployment_status_tasks:
runs-on: ubuntu-latest
if: github.event.deployment_status.state == 'success'
steps:
- uses: otto-de/purge-deprecated-workflow-runs@v2
with:
# disable default-behaviour of deleting orphaned runs
remove-obsolete: false
# remove previously cancelled runs of *all* workflows
remove-cancelled: true
# remove failed runs of *this* workflow
remove-failed: |
${{ github.workflow }}
# remove previously skipped runs of workflows with given names
remove-skipped: |
Unit Tests
Deploy
The following example will remove all workflow runs that are older than 4 weeks and all runs of the current workflow older than 1 day:
name: Weekly purge of any workflow runs older than four weeks and current workflow runs older than one day
on:
schedule:
- cron: '0 0 * * 0'
jobs:
purge_old_workflows:
runs-on: ubuntu-latest
steps:
- uses: otto-de/purge-deprecated-workflow-runs@v2
with:
remove-older-than: |
4w *
1d ${{ github.workflow }}