name: Cleanup Image Tags

on:
  schedule:
    - cron: '0 0 * * SAT'
  delete:
  pull_request:
    types:
      - closed
  push:
    paths:
      - ".github/workflows/cleanup-tags.yml"
      - ".github/scripts/cleanup-tags.py"
      - ".github/scripts/common.py"

env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
  cleanup:
    name: Cleanup Image Tags
    runs-on: ubuntu-20.04
    permissions:
      packages: write
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
      -
        name: Login to Github Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      -
        name: Set up Python
        uses: actions/setup-python@v3
        with:
          python-version: "3.9"
      -
        name: Install requests
        run: |
          python -m pip install requests
      -
        name: Cleanup feature tags
        run: |
          python ${GITHUB_WORKSPACE}/.github/scripts/cleanup-tags.py --loglevel info --delete
