|
| 1 | +name: "Clean up runner disk space" |
| 2 | +description: "Removes large, non-essential toolsets to free up disk space on the runner." |
| 3 | + |
| 4 | +runs: |
| 5 | + using: "composite" |
| 6 | + steps: |
| 7 | + - name: Free up disk space |
| 8 | + shell: bash |
| 9 | + run: | |
| 10 | + set -euo pipefail |
| 11 | +
|
| 12 | + echo "Removing large toolsets to free up disk space..." |
| 13 | + echo "Disk space before cleanup:" |
| 14 | + df -h || true |
| 15 | +
|
| 16 | + shopt -s nullglob |
| 17 | +
|
| 18 | + remove_path() { |
| 19 | + local path="$1" |
| 20 | + if [ -e "$path" ] || [ -L "$path" ]; then |
| 21 | + echo "Removing $path" |
| 22 | + sudo rm -rf "$path" |
| 23 | + fi |
| 24 | + } |
| 25 | +
|
| 26 | + # Remove large toolsets and caches. |
| 27 | + remove_path /usr/share/dotnet |
| 28 | + remove_path /usr/local/lib/android |
| 29 | + remove_path /opt/ghc |
| 30 | + remove_path /usr/share/swift |
| 31 | + for path in /usr/local/julia*; do remove_path "$path"; done |
| 32 | + remove_path /opt/hostedtoolcache |
| 33 | +
|
| 34 | + # Remove caches. |
| 35 | + remove_path /usr/local/share/boost |
| 36 | + if [ -n "${AGENT_TOOLSDIRECTORY:-}" ]; then |
| 37 | + remove_path "$AGENT_TOOLSDIRECTORY" |
| 38 | + fi |
| 39 | +
|
| 40 | + # Remove docker images to save space. |
| 41 | + if command -v docker >/dev/null 2>&1; then |
| 42 | + docker image prune -a -f || true |
| 43 | + else |
| 44 | + echo "Docker not available; skipping image prune." |
| 45 | + fi |
| 46 | +
|
| 47 | + # Remove large apt packages when available. |
| 48 | + if command -v apt-get >/dev/null 2>&1; then |
| 49 | + sudo apt-get remove -y \ |
| 50 | + '^aspnetcore-.*' \ |
| 51 | + '^dotnet-.*' \ |
| 52 | + '^llvm-.*' \ |
| 53 | + 'php.*' \ |
| 54 | + '^mongodb-.*' \ |
| 55 | + '^mysql-.*' \ |
| 56 | + azure-cli \ |
| 57 | + google-chrome-stable \ |
| 58 | + firefox \ |
| 59 | + powershell \ |
| 60 | + mono-devel \ |
| 61 | + libgl1-mesa-dri 2>/dev/null || true |
| 62 | + sudo apt-get autoremove -y || true |
| 63 | + sudo apt-get clean || true |
| 64 | + else |
| 65 | + echo "apt-get not available; skipping package removals." |
| 66 | + fi |
| 67 | +
|
| 68 | + echo "Disk space after cleanup:" |
| 69 | + df -h || true |
0 commit comments