name: "Clean up runner disk space"
description: "Removes large, non-essential toolsets to free up disk space on the runner."

runs:
  using: "composite"
  steps:
    - name: Free up disk space
      shell: bash
      run: |
        echo "Removing large toolsets to free up disk space..."
        echo "Disk space before cleanup:"
        df -h

        # Remove dotnet to save disk space.
        sudo rm -rf /usr/share/dotnet
        # Remove android to save disk space.
        sudo rm -rf /usr/local/lib/android
        # Remove ghc to save disk space.
        sudo rm -rf /opt/ghc
        # Remove large packages.
        sudo rm -rf /usr/share/swift
        sudo rm -rf /usr/local/julia*
        sudo rm -rf /opt/hostedtoolcache

        # Remove docker images to save space.
        docker image prune -a -f || true

        # Remove large apt packages.
        sudo apt-get remove -y '^aspnetcore-.*' '^dotnet-.*' '^llvm-.*' 'php.*' '^mongodb-.*' '^mysql-.*' azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri 2>/dev/null || true
        sudo apt-get autoremove -y
        sudo apt-get clean

        # Remove caches.
        sudo rm -rf /usr/local/share/boost
        sudo rm -rf "$AGENT_TOOLSDIRECTORY"

        echo "Disk space after cleanup:"
        df -h
