Skip to content

Remove github workflow runs from current repository

License

Notifications You must be signed in to change notification settings

otto-de/purge-deprecated-workflow-runs

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

🧹 Purge workflow runs action Unit Test

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.

Inputs

Name Description Default 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-skipped Remove skipped workflows false true

remarks on the input fields

token

  • Using github.token usually works, unless the actions are not scoped with repo rights. For more details, see the GITHUB_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".

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's name. 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's name. On match the run will be removed.

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's name. On match the run will be removed.

Example usage

Remove failed workflows

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

Advanced usage

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