Skip to content

Commit

Permalink
Free disk space on GHA worker nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo committed Oct 10, 2023
1 parent 5600cfd commit 257ecdd
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
70 changes: 70 additions & 0 deletions .github/bin/free-disk-space.sh
Original file line number Diff line number Diff line change
@@ -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 .
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 257ecdd

Please sign in to comment.