Git Product home page Git Product logo

delete-workflow-runs's Introduction

delete-workflow-runs v2

The GitHub action to delete workflow runs in a repository. This action (written in JavaScript) wraps two Workflow Runs API:

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.

What's new?

  • Add the input parameter "delete_run_by_conclusion_pattern" - useful for skipped workflow runs.
  • Add the input parameter "delete_workflow_by_state_pattern" and "dry_run".
  • Add ability to filter workflows by workflow filename (in addition to the name)
  • Add ability to filter workflows by state
  • Add ability to perform a 'dry run' which logs the changes but doesn't perform the actual deletion.

Inputs

1. token

Required: YES

Default: ${{ github.token }}

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 the GITHUB_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".

2. repository

Required: YES

Default: ${{ github.repository }}

The name of the repository where the workflow runs are on.

3. retain_days

Required: YES

Default: 30

The number of days that is used to compare with the retention days of each workflow.

4. keep_minimum_runs

Required: YES

Default: 6

The minimum runs to keep for each workflow.

5. delete_workflow_pattern

Required: NO

Default: 'all'

The name or filename of the workflow. if not set then it will target all workflows.

6. delete_workflow_by_state_pattern

Required: NO

Default: 'all'

Remove workflow by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually

7. delete_run_by_conclusion_pattern

Required: NO

Default: 'all'

Remove workflow by conclusion: action_required, cancelled, failure, skipped, success

8. dry_run

Required: NO

Only log actions, do not perform any delete operations.

Examples

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.
manual workflow

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 or filename of the workflow. if not set then it will target all workflows.'
        required: false
      delete_workflow_by_state_pattern:
        description: 'Remove workflow by state: active, deleted, disabled_fork, disabled_inactivity, disabled_manually'
        required: true
        default: "All"
        type: choice
        options:
          - "All"
          - active
          - deleted
          - disabled_inactivity
          - disabled_manually
      delete_run_by_conclusion_pattern:
        description: 'Remove workflow by conclusion: action_required, cancelled, failure, skipped, success'
        required: true
        default: "All"
        type: choice
        options:
          - "All"
          - action_required
          - cancelled
          - failure
          - skipped
          - success
      dry_run:
        description: 'Only log actions, do not perform any delete operations.'
        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 }}
          delete_workflow_by_state_pattern: ${{ github.event.inputs.delete_workflow_by_state_pattern }}
          delete_run_by_conclusion_pattern: ${{ github.event.inputs.delete_run_by_conclusion_pattern }}
          dry_run: ${{ github.event.inputs.dry_run }}

License

The scripts and documentation in this project are released under the MIT License.

delete-workflow-runs's People

Contributors

brightran avatar mattraks avatar jeremylong avatar ansaya avatar seivan avatar simply-inventive avatar odedlaz avatar tspascoal avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.