diff --git a/.github/workflows/pr_actions-smoke-test.yml b/.github/workflows/pr_actions-smoke-test.yml index 885d131..9fc5f10 100644 --- a/.github/workflows/pr_actions-smoke-test.yml +++ b/.github/workflows/pr_actions-smoke-test.yml @@ -8,6 +8,7 @@ on: - .github/workflows/pr_actions-smoke-test.yml - build-container-image/action.yml - build-product-image/action.yml + - free-disk-space/action.yml - publish-image/action.yml - publish-index-manifest/action.yml - shard/action.yml diff --git a/README.md b/README.md index bc1eb44..52f1c3d 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ particular step in a workflow. - [build-container-image](./build-container-image/README.md) - [build-product-image](./build-product-image/README.md) +- [free-disk-space](./free-disk-space/README.md) - [publish-image](./publish-image/README.md) - [publish-index-manifest](./publish-index-manifest/README.md) - [run-pre-commit](./run-pre-commit/README.md) diff --git a/build-container-image/action.yml b/build-container-image/action.yml index 89ded41..358003c 100644 --- a/build-container-image/action.yml +++ b/build-container-image/action.yml @@ -42,21 +42,8 @@ outputs: runs: using: composite steps: - - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1 - with: - # This might remove tools that are actually needed, if set to "true" but - # frees about 6 GB. - tool-cache: false - - # All of these default to true, but feel free to set to "false" if - # necessary for your workflow. - android: true - dotnet: true - haskell: true - large-packages: true - docker-images: true - swap-storage: true + - name: Free Disk Space + uses: ./free-disk-space - name: Setup Docker Buildx uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 diff --git a/build-product-image/action.yml b/build-product-image/action.yml index b4c1287..8b7a755 100644 --- a/build-product-image/action.yml +++ b/build-product-image/action.yml @@ -29,21 +29,8 @@ outputs: runs: using: composite steps: - - name: Free Disk Space (Ubuntu) - uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1 - with: - # This might remove tools that are actually needed, if set to "true" but - # frees about 6 GB. - tool-cache: false - - # All of these default to true, but feel free to set to "false" if - # necessary for your workflow. - android: true - dotnet: true - haskell: true - large-packages: true - docker-images: true - swap-storage: true + - name: Free Disk Space + uses: ./free-disk-space - name: Setup Docker Buildx uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1 diff --git a/free-disk-space/README.md b/free-disk-space/README.md new file mode 100644 index 0000000..a498d94 --- /dev/null +++ b/free-disk-space/README.md @@ -0,0 +1,27 @@ +# `free-disk-space` + +> Manifest: [free-disk-space/action.yml][free-disk-space] + +This action This action frees up disk space on a runner. + +It is based on `jlumbroso/free-disk-space`and runs cleanup tasks in parallel where possible, and hides the STDOUT output of each task to reduce noise in workflow runs. + +> [!NOTE] +> This action is used by the [build-container-image] and [build-product-image] actions. + +## Inputs and Outputs + +> [!TIP] +> For descriptions of the inputs and outputs, see the complete [free-disk-space] action. + +### Inputs + +None + +### Outputs + +None + +[free-disk-space]: ./action.yml +[build-container-image]: ../build-container-image/action.yml +[build-product-image]: ../build-product-image/action.yml diff --git a/free-disk-space/action.yml b/free-disk-space/action.yml new file mode 100644 index 0000000..bcad2a2 --- /dev/null +++ b/free-disk-space/action.yml @@ -0,0 +1,120 @@ +--- +name: Free Disk Space +description: This action frees up disk space on a runner. +inputs: + product-name: + description: The name of the product to build via bake (directory name) + required: true + config-file: + description: Path the the config file used to generate the shard indices + default: ./conf.py +outputs: + versions: + description: A list of product versions + value: ${{ steps.generate_shards.outputs.VERSIONS }} +runs: + using: composite + steps: + - name: Free Disk Space (Parallel) + shell: bash + run: | + # WARNING: `set -e` is not set as we purposefully want this to run optimistically. + + function cleanup_android() { + ( + sudo rm -rf /usr/local/lib/android || true + )>/dev/null + } + + function cleanup_apt() { + ( + sudo apt-get remove --fix-missing -y '^aspnetcore-.*' \ + '^dotnet-.*' \ + '^llvm-.*' \ + 'php.*' \ + '^mongodb-.*' \ + '^mysql-.*' \ + azure-cli \ + google-chrome-stable \ + firefox \ + powershell \ + mono-devel \ + libgl1-mesa-dri \ + google-cloud-sdk \ + google-cloud-cli || true + sudo apt-get autoremove -y + sudo apt-get clean + )>/dev/null + } + + function cleanup_dotnet() { + ( + sudo rm -rf /usr/share/dotnet || true + )>/dev/null + } + + function cleanup_haskell() { + ( + sudo rm -rf /opt/ghc || true + sudo rm -rf /usr/local/.ghcup || true + )>/dev/null + } + + function cleanup_docker() { + ( + sudo docker image prune --all --force || true + )>/dev/null + } + + function cleanup_agenttools() { + ( + sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true + )>/dev/null + } + + function disable_swap() { + ( + sudo swapoff -a || true + sudo rm -f /mnt/swapfile || true + free -h + )>/dev/null + } + + # The bash `time` built-in can be given subshells, and the output format + # is configured via the TIMEFORMAT environment variable. + # The binary `time` output format can be configured via a `--format` + # flag. + # Since we are calling the cleanup functions in parallel, we need to + # wrap the built-in `time` so that each concurrent invokation doesn't + # affect the output format of another. + function time_it() { + local MESSAGE="$1" + local FUNCTION="$2" + local TIMEFORMAT="$MESSAGE (%Rs)" + time "$FUNCTION" + } + + echo "::group::Disk usage before" + df -h / + echo "::endgroup::" + + echo "::group::Parallel cleanup" + + time_it 'Removed Android libraries' cleanup_android & + time_it 'Removed apt packages' cleanup_apt & + time_it 'Removed dotnet packages' cleanup_dotnet & + time_it 'Removed haskell' cleanup_haskell & + time_it 'Pruned docker images' cleanup_docker & + time_it 'Disabled swap' disable_swap & + + # This might remove tools that are actually needed, if set to "true" but + # frees about 6 GB. + # time_it 'Removed agent tools' cleanup_agenttools & + + echo "Waiting for cleanup tasks" + wait + echo "::endgroup::" + + echo "::group::Disk usage after" + df -h / + echo "::endgroup::"