Skip to content

Action — cleanup-runs ​

Deletes the old workflow runs of the repository, with their logs and artifacts, oldest first, and keeps the recent ones. Talks to the REST API with curl and jq: no GitHub CLI needed, no checkout. cleanup-runs.yml wraps it and documents the retention policy.

Usage ​

yaml
permissions:
  actions: write
  pull-requests: read

steps:
  - uses: KevinDeBenedetti/github-workflows/.github/actions/cleanup-runs@main
    with:
      keep-runs: 5
      dry-run: true

Inputs ​

InputDefaultDescription
keep-runs10Most recent runs kept per workflow, whatever their age (0 to 100)
older-than-days30Age, in days, before a run can be deleted (1 or more)
max-deletions500Runs deleted at most in one run (1 to 1000)
dry-runfalseLog what would be deleted, delete nothing
github-token${{ github.token }}Token with actions: write and pull-requests: read

Outputs ​

OutputDescription
deletedRuns deleted by this run (in a dry run, the runs that would be)
remainingRuns left for a later run by max-deletions

Notes ​

  • The token goes to curl through a header file, never on a command line.
  • Workflow paths are printed with any character outside letters, digits and ._/@- replaced by _: a workflow file cannot write a workflow command into the log.
  • The rules are documented at the top of cleanup-runs.sh, and the deletions are counted per workflow in the job summary.