|
| 1 | +--- |
| 2 | +name: Free Disk Space |
| 3 | +description: This action frees up disk space on a runner. |
| 4 | +inputs: |
| 5 | + product-name: |
| 6 | + description: The name of the product to build via bake (directory name) |
| 7 | + required: true |
| 8 | + config-file: |
| 9 | + description: Path the the config file used to generate the shard indices |
| 10 | + default: ./conf.py |
| 11 | +outputs: |
| 12 | + versions: |
| 13 | + description: A list of product versions |
| 14 | + value: ${{ steps.generate_shards.outputs.VERSIONS }} |
| 15 | +runs: |
| 16 | + using: composite |
| 17 | + steps: |
| 18 | + - name: Free Disk Space (Parallel) |
| 19 | + shell: bash |
| 20 | + run: | |
| 21 | + # WARNING: `set -e` is not set as we purposefully want this to run optimistically. |
| 22 | +
|
| 23 | + function cleanup_android() { |
| 24 | + ( |
| 25 | + sudo rm -rf /usr/local/lib/android || true |
| 26 | + )>/dev/null |
| 27 | + } |
| 28 | +
|
| 29 | + function cleanup_apt() { |
| 30 | + ( |
| 31 | + sudo apt-get remove --fix-missing -y '^aspnetcore-.*' \ |
| 32 | + '^dotnet-.*' \ |
| 33 | + '^llvm-.*' \ |
| 34 | + 'php.*' \ |
| 35 | + '^mongodb-.*' \ |
| 36 | + '^mysql-.*' \ |
| 37 | + azure-cli \ |
| 38 | + google-chrome-stable \ |
| 39 | + firefox \ |
| 40 | + powershell \ |
| 41 | + mono-devel \ |
| 42 | + libgl1-mesa-dri \ |
| 43 | + google-cloud-sdk \ |
| 44 | + google-cloud-cli || true |
| 45 | + sudo apt-get autoremove -y |
| 46 | + sudo apt-get clean |
| 47 | + )>/dev/null |
| 48 | + } |
| 49 | +
|
| 50 | + function cleanup_dotnet() { |
| 51 | + ( |
| 52 | + sudo rm -rf /usr/share/dotnet || true |
| 53 | + )>/dev/null |
| 54 | + } |
| 55 | +
|
| 56 | + function cleanup_haskell() { |
| 57 | + ( |
| 58 | + sudo rm -rf /opt/ghc || true |
| 59 | + sudo rm -rf /usr/local/.ghcup || true |
| 60 | + )>/dev/null |
| 61 | + } |
| 62 | +
|
| 63 | + function cleanup_docker() { |
| 64 | + ( |
| 65 | + sudo docker image prune --all --force || true |
| 66 | + )>/dev/null |
| 67 | + } |
| 68 | +
|
| 69 | + function cleanup_agenttools() { |
| 70 | + ( |
| 71 | + sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true |
| 72 | + )>/dev/null |
| 73 | + } |
| 74 | +
|
| 75 | + function disable_swap() { |
| 76 | + ( |
| 77 | + sudo swapoff -a || true |
| 78 | + sudo rm -f /mnt/swapfile || true |
| 79 | + free -h |
| 80 | + )>/dev/null |
| 81 | + } |
| 82 | +
|
| 83 | + # The bash `time` built-in can be given subshells, and the output format |
| 84 | + # is configured via the TIMEFORMAT environment variable. |
| 85 | + # The binary `time` output format can be configured via a `--format` |
| 86 | + # flag. |
| 87 | + # Since we are calling the cleanup functions in parallel, we need to |
| 88 | + # wrap the built-in `time` so that each concurrent invokation doesn't |
| 89 | + # affect the output format of another. |
| 90 | + function time_it() { |
| 91 | + local MESSAGE="$1" |
| 92 | + local FUNCTION="$2" |
| 93 | + local TIMEFORMAT="$MESSAGE (%Rs)" |
| 94 | + time "$FUNCTION" |
| 95 | + } |
| 96 | +
|
| 97 | + echo "::group::Disk usage before" |
| 98 | + df -h / |
| 99 | + echo "::endgroup::" |
| 100 | +
|
| 101 | + echo "::group::Parallel cleanup" |
| 102 | +
|
| 103 | + time_it 'Removed Android libraries' cleanup_android & |
| 104 | + time_it 'Removed apt packages' cleanup_apt & |
| 105 | + time_it 'Removed dotnet packages' cleanup_dotnet & |
| 106 | + time_it 'Removed haskell' cleanup_haskell & |
| 107 | + time_it 'Pruned docker images' cleanup_docker & |
| 108 | + time_it 'Disabled swap' disable_swap & |
| 109 | +
|
| 110 | + # This might remove tools that are actually needed, if set to "true" but |
| 111 | + # frees about 6 GB. |
| 112 | + # time_it 'Removed agent tools' cleanup_agenttools & |
| 113 | +
|
| 114 | + echo "Waiting for cleanup tasks" |
| 115 | + wait |
| 116 | + echo "::endgroup::" |
| 117 | +
|
| 118 | + echo "::group::Disk usage after" |
| 119 | + df -h / |
| 120 | + echo "::endgroup::" |
0 commit comments