name: Prune dev tags

# Weekly housekeeping: prune legacy CalVer git tags + GHCR images
# (dev-YYYY.MM.N / stable-YYYY.MM.N) on a KEEP_MONTHS retention window
# (current + previous month by default). Manual trigger supports a
# dry-run and a KEEP_MONTHS override. Floating aliases (:stable, :dev,
# *-latest) are git-tagless and never matched, so they are never pruned.
# Scheduled runs always prune for real; use workflow_dispatch with
# dry_run=true to preview.

on:
  schedule:
    - cron: '0 4 * * 0'  # Sundays 04:00 UTC
  workflow_dispatch:
    inputs:
      dry_run:
        description: 'Dry-run only — list tags that would be pruned, do not delete'
        type: boolean
        default: true
      keep_months:
        description: 'Keep current month + this many previous months (e.g. 1 = 2 months total)'
        type: string
        default: '1'

permissions:
  contents: write   # delete git tags
  packages: write   # delete GHCR image versions

jobs:
  prune:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
          fetch-tags: true

      - name: Run prune
        env:
          GITHUB_REPOSITORY: ${{ github.repository }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          KEEP_MONTHS: ${{ inputs.keep_months || '1' }}
          PRUNE_DRY_RUN: ${{ inputs.dry_run && '1' || '0' }}
        run: bash scripts/ops/prune-dev-tags.sh
