diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index 732feab71377..c455d40906b6 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -7,6 +7,9 @@ inputs: cache: description: "Cache Maven repo (true/false/restore)" default: true + cleanup-node: + description: "Clean up node (true/false) to increase free disk space" + default: false # Disabled by default as it adds ~4 minutes of test runtime. Should be enabled case by case. download_dependencies: description: "Download all Maven dependencies so Maven can work in offline mode" default: true @@ -33,6 +36,10 @@ runs: - name: Fetch base ref to find merge-base for GIB shell: bash run: .github/bin/git-fetch-base-ref.sh + - name: Free additional disk space + if: ${{ format('{0}', inputs.cleanup-node) == 'true' }} + shell: bash + run: ./.github/bin/free-disk-space.sh - uses: actions/setup-java@v3 if: ${{ inputs.java-version != '' }} with: diff --git a/.github/bin/free-disk-space.sh b/.github/bin/free-disk-space.sh new file mode 100755 index 000000000000..ef80026b7406 --- /dev/null +++ b/.github/bin/free-disk-space.sh @@ -0,0 +1,70 @@ +#!/bin/bash +set -euo pipefail + +function list_installed_packages() +{ + apt list --installed "$1" 2>/dev/null | awk -F'/' 'NR>1{print $1}' | tr '\n' ' ' +} + +function free_up_disk_space_ubuntu() +{ + local packages=( + 'azure-cli' + 'aspnetcore-*' + 'dotnet-*' + 'firefox*' + 'google-chrome-*' + 'google-cloud-*' + 'libmono-*' + 'llvm-*' + 'imagemagick' + 'postgresql-*' + 'rubu-*' + 'spinxsearch' + 'unixodbc-dev' + 'mercurial' + 'esl-erlang' + 'microsoft-edge-stable' + 'mono-*' + 'msbuild' + 'mysql-server-core-*' + 'php-*' + 'php7*' + 'powershell*' + 'mongo*' + 'microsoft-edge*' + 'subversion') + + for package in "${packages[@]}"; do + installed_packages=$(list_installed_packages "${package}") + echo "Removing packages by pattern ${package}: ${installed_packages}" + sudo apt-get --auto-remove -y purge ${installed_packages} + done + + echo "Autoremoving packages" + sudo apt-get autoremove -y + + echo "Autocleaning" + sudo apt-get autoclean -y + + echo "Removing toolchains" + sudo rm -rf \ + /usr/local/graalvm \ + /usr/local/lib/android/ \ + /usr/share/dotnet/ \ + /opt/ghc/ \ + /usr/local/share/boost/ \ + "${AGENT_TOOLSDIRECTORY}" + + echo "Prune docker images" + sudo docker system prune --all -f +} + +echo "Disk space usage before cleaning:" +df -k . + +echo "Clearing up disk usage:" +free_up_disk_space_ubuntu + +echo "Disk space usage after cleaning:" +df -k . diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5803e6128711..54406cb7c4cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,6 +96,8 @@ jobs: github.event.client_payload.pull_request.head.sha == github.event.client_payload.slash_command.args.named.sha && format('refs/pull/{0}/head', github.event.client_payload.pull_request.number) || '' }} - uses: ./.github/actions/setup + with: + cleanup-node: true - name: Maven Install run: | export MAVEN_OPTS="${MAVEN_INSTALL_OPTS}"