Skip to content

Action — cleanup-deployments ​

Deletes the old deployment records of the repository, oldest first. It keeps the keep most recent deployments of each environment and those younger than older-than-days, and gives each deployment the inactive status before deleting it. The cleanup-deployments workflow runs it.

Usage ​

yaml
permissions:
  deployments: write
steps:
  - uses: KevinDeBenedetti/github-workflows/.github/actions/cleanup-deployments@main
    with:
      dry-run: true

Inputs ​

InputDefaultDescription
keep5Most recent deployments kept per environment (1 to 100)
older-than-days30Age, in days, before a deployment can be deleted (0 or more)
max-deletions200Deletions at most in one run (1 to 400), two requests each
dry-runfalseLog what would be deleted, delete nothing
github-token${{ github.token }}Token with deployments: write

Outputs ​

OutputDescription
deletedDeployments deleted by this run (in a dry run, those that would be)
remainingDeployments left for a later run by max-deletions

Notes ​

  • Needs bash, curl and jq: no GitHub CLI.
  • The script is cleanup-deployments.sh; its tests are in tests/cleanup-deployments.bats.