name: DigitalOcean
on:
  workflow_dispatch:
  workflow_call:

jobs:
  garbage-collection:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Install doctl
        uses: digitalocean/action-doctl@5727c67aa3c2c34ae9462d5a0ecfea8a1b31e5ce # v2
        with:
          token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
      - name: Run garbage collection
        run: |
          # --force: Required for CI to skip confirmation prompts
          # --include-untagged-manifests: Deletes unreferenced manifests to maximize space
          doctl registry garbage-collection start --force --include-untagged-manifests
      - name: Send email on failure
        uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
        if: ${{ failure() }}
        with:
          smtp_username: ${{ secrets.SMTP_USERNAME }}
          smtp_password: ${{ secrets.SMTP_PASSWORD }}
