name: Bazel Cache Cleanup

on:
  schedule:
    # Run weekly on Sunday at 00:00 UTC
    - cron: '0 0 * * 0'
  workflow_dispatch:  # Allow manual trigger

jobs:
  cleanup:
    runs-on: [self-hosted, bazel]

    steps:
      - name: Checkout
        uses: actions/checkout@v6
        with:
          lfs: false

      - name: Show disk usage before cleanup
        run: |
          echo "=== Disk usage before cleanup ==="
          BAZEL_USER_ROOT="/private/var/tmp/_bazel_$(whoami)"
          echo "Bazel user root: $BAZEL_USER_ROOT"
          du -sh "$BAZEL_USER_ROOT" 2>/dev/null || echo "Not found"
          df -h .

      - name: Run bazel clean
        run: |
          echo "=== Running bazel clean ==="
          bazel clean
          echo "Clean complete"

      - name: Show disk usage after cleanup
        run: |
          echo "=== Disk usage after cleanup ==="
          BAZEL_USER_ROOT="/private/var/tmp/_bazel_$(whoami)"
          du -sh "$BAZEL_USER_ROOT" 2>/dev/null || echo "Not found"
          df -h .
