name: 'Util: Cleanup CI Docker Images'

on:
  schedule:
    # Daily cleanup at 3 AM UTC
    - cron: '0 3 * * *'

jobs:
  cleanup:
    name: 'Delete stale CI images'
    runs-on: ubuntu-slim
    permissions:
      packages: write
      contents: read
    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          sparse-checkout: .github/scripts
          sparse-checkout-cone-mode: false

      - name: Delete stale CI images
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          GHCR_ORG: ${{ github.repository_owner }}
          GHCR_REPO: ${{ github.event.repository.name }}
        run: node .github/scripts/cleanup-ghcr-images.mjs --stale 3
