GitHub Action
Delete workflow runs
The GitHub action to delete workflow runs in a repository. This action (written in JavaScript) wraps two Workflow Runs API:
-
List repository workflows -- Lists the workflows in a repository.
-
List workflow runs -- List all workflow runs for a workflow.
-
Delete a workflow run -- Delete a specific workflow run.
The action will calculate the number of days that each workflow run has been retained so far, then use this number to compare with the number you specify for the input parameter "retain_days
". If the retention days of the workflow run has reached (equal to or greater than) the specified number, the workflow run will be deleted.
- Add the input parameter "
delete_workflow_pattern
". Fill in the specified workflow name, this workflow will be processed, if no workflow is specified, all workflows in the repository will be processed.
The token used to authenticate.
- If the workflow runs are in the current repository where the action is running, using
github.token
is OK. More details, see theGITHUB_TOKEN
. - If the workflow runs are in another repository, you need to use a personal access token (PAT) that must have the
repo
scope. More details, see "Creating a personal access token".
The name of the repository where the workflow runs are on.
The number of days that is used to compare with the retention days of each workflow.
The minimum runs to keep for each workflow.
The name of the workflow. if not set then it will target all workflows.
In scheduled workflow, see schedule event.
Tip: Using scheduled workflow is the recommended way that can periodically, automatically delete old workflow runs.
name: Delete old workflow runs
on:
schedule:
- cron: '0 0 1 * *'
# Run monthly, at 00:00 on the 1st day of month.
jobs:
del_runs:
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: 30
keep_minimum_runs: 6
In manual triggered workflow, see workflow_dispatch event.
In this way, you can manually trigger the workflow at any time to delete old workflow runs.
name: Delete old workflow runs
on:
workflow_dispatch:
inputs:
days:
description: 'Number of days.'
required: true
default: 30
minimum_runs:
description: 'The minimum runs to keep for each workflow.'
required: true
default: 6
delete_workflow_pattern:
description: 'The name of the workflow. if not set then it will target all workflows.'
required: false
jobs:
del_runs:
runs-on: ubuntu-latest
steps:
- name: Delete workflow runs
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: ${{ github.event.inputs.days }}
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
delete_workflow_pattern: ${{ github.event.inputs.delete_workflow_pattern }}
The scripts and documentation in this project are released under the MIT License.