Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 85 additions & 24 deletions src/ci/scripts/free-disk-space-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,25 @@ removeUnusedFilesAndDirs() {
)

if isGitHubRunner; then
# Paths common to all runners (both x86 and ARM)
to_remove+=(
"/usr/local/aws-sam-cli"
"/usr/local/doc/cmake"
"/usr/local/julia"*
"/usr/local/lib/android"
"/usr/local/share/chromedriver-"*
"/usr/local/share/chromium"
"/usr/local/share/cmake-"*
"/usr/local/share/edge_driver"
"/usr/local/share/emacs"
"/usr/local/share/gecko_driver"
"/usr/local/share/icons"
"/usr/local/share/powershell"
"/usr/local/share/vcpkg"
"/usr/local/share/vim"
"/usr/share/apache-maven-"*
"/usr/share/gradle-"*
"/usr/share/kotlinc"
"/usr/share/miniconda"
"/usr/share/php"
"/usr/share/ri"
"/usr/share/swift"

# binaries
"/usr/local/bin/azcopy"
"/usr/local/bin/bicep"
"/usr/local/bin/ccmake"
"/usr/local/bin/cmake-"*
"/usr/local/bin/cmake"
Expand All @@ -135,16 +128,53 @@ removeUnusedFilesAndDirs() {
"/usr/local/bin/phpunit"
"/usr/local/bin/pulumi-"*
"/usr/local/bin/pulumi"
"/usr/local/bin/stack"

# Haskell runtime
"/usr/local/.ghcup"

# Azure
"/opt/az"
"/usr/share/az_"*

# Microsoft Edge and powershell
"/opt/microsoft"

"/opt/pipx"
"/opt/pipx_bin"
Comment on lines +136 to +140
Copy link
Copy Markdown
Member Author

@marcoieni marcoieni Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These paths are new

View changes since the review

)

# Paths only present in x86 runners
local github_runner_x86_paths=(
Copy link
Copy Markdown
Member Author

@marcoieni marcoieni Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I extracted these paths from the array above because they are not present in arm. Trying to remove them was emitting a warning.

View changes since the review

"/usr/local/julia"*
"/usr/local/lib/android"
"/usr/local/share/chromedriver-"*
"/usr/local/share/chromium"
"/usr/local/share/edge_driver"
"/usr/share/gradle-"*
"/usr/share/miniconda"

# binaries
"/usr/local/bin/bicep"
"/usr/local/bin/stack"

# Haskell runtime
"/usr/local/.ghcup"
)

if isX86; then
to_remove+=("${github_runner_x86_paths[@]}")
else
# warn if x86-only paths are present in other runners
local existing_github_runner_x86_paths=()
local x86_path
for x86_path in "${github_runner_x86_paths[@]}"; do
if [ -e "$x86_path" ]; then
existing_github_runner_x86_paths+=("$x86_path")
fi
done

if [ "${#existing_github_runner_x86_paths[@]}" -ne 0 ]; then
echo "::warning::You can remove the following paths to save space: ${existing_github_runner_x86_paths[*]}"
fi
fi

if [ -n "${AGENT_TOOLSDIRECTORY:-}" ]; then
# Environment variable set by GitHub Actions
to_remove+=(
Expand Down Expand Up @@ -201,10 +231,22 @@ cleanPackages() {
'^dotnet-.*'
'^llvm-.*'
'^mongodb-.*'
'^temurin-.*-jdk'
'buildah'
'firefox'
'google-cloud-cli'
'google-cloud-sdk'
'kubectl'
'libgl1-mesa-dri'
'mono-devel'
'php.*'
'podman'
'skopeo'
)
local x86_only_packages=(
'google-chrome-stable'
'microsoft-edge-stable'
Copy link
Copy Markdown
Member Author

@marcoieni marcoieni Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edge and the new packages from temurin to skopeo are new (they weren't removed before)

View changes since the review

'powershell'
)

if isGitHubRunner; then
Expand All @@ -213,12 +255,20 @@ cleanPackages() {
)

if isX86; then
packages+=(
'google-chrome-stable'
'google-cloud-cli'
'google-cloud-sdk'
'powershell'
)
packages+=("${x86_only_packages[@]}")
else
# warn if x86-only packages are installed on other runners
local installed_x86_only_packages=()
local package
for package in "${x86_only_packages[@]}"; do
if dpkg-query -W -f='${binary:Package}\n' "$package" >/dev/null 2>&1; then
installed_x86_only_packages+=("$package")
fi
done

if [ "${#installed_x86_only_packages[@]}" -ne 0 ]; then
echo "::warning::You can remove the following packages to save space: ${installed_x86_only_packages[*]}"
fi
fi
else
packages+=(
Expand All @@ -235,11 +285,19 @@ cleanPackages() {
|| echo "::warning::The command [sudo apt-get clean] failed"
}

# Remove Docker images.
# Ubuntu 22 runners have docker images already installed.
# They aren't present in ubuntu 24 runners.
# Remove preinstalled Docker images.
Copy link
Copy Markdown
Member Author

@marcoieni marcoieni Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this comment because there are some docker images in ubuntu 24 as well.

View changes since the review

cleanDocker() {
local images
images=$(sudo docker image ls -q)

if [ -z "$images" ]; then
echo "=> No docker images to remove."
return
fi
Copy link
Copy Markdown
Member Author

@marcoieni marcoieni Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attempting to remove all docker images when there were none, produced a warning (because the measured saved space was less than zero)

View changes since the review


echo "=> Removing the following docker images:"
# Use "docker image ls" without "-q" to get the full table output which contains
# also the image names and sizes.
sudo docker image ls
echo "=> Removing docker images..."
sudo docker image prune --all --force || true
Expand All @@ -253,7 +311,8 @@ cleanSwap() {
}

sufficientSpaceEarlyExit() {
local available_space_kb=$(df -k . --output=avail | tail -n 1)
local available_space_kb
available_space_kb=$(df -k . --output=avail | tail -n 1)
Copy link
Copy Markdown
Member Author

@marcoieni marcoieni Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and below I fixed a shellcheck lint that suggested to declare the variable before assigning it

View changes since the review


if [ "$available_space_kb" -ge "$space_target_kb" ]; then
echo "Sufficient disk space available (${available_space_kb}KB >= ${space_target_kb}KB). Skipping cleanup."
Expand All @@ -267,7 +326,8 @@ sufficientSpaceEarlyExit() {
checkAlternative() {
local gha_alt_disk="/mnt"

local available_space_kb=$(df -k "$gha_alt_disk" --output=avail | tail -n 1)
local available_space_kb
available_space_kb=$(df -k "$gha_alt_disk" --output=avail | tail -n 1)

# mount options that trade durability for performance
# ignore-tidy-linelength
Expand All @@ -276,7 +336,8 @@ checkAlternative() {
# GHA has a 2nd disk mounted at /mnt that is almost empty.
# Check if it's a valid mountpoint and it has enough available space.
if mountpoint "$gha_alt_disk" && [ "$available_space_kb" -ge "$space_target_kb" ]; then
local blkdev=$(df -k "$gha_alt_disk" --output=source | tail -n 1)
local blkdev
blkdev=$(df -k "$gha_alt_disk" --output=source | tail -n 1)
echo "Sufficient space available on $blkdev mounted at $gha_alt_disk"
# see cleanSwap(), swapfile may be mounted under /mnt
sudo swapoff -a || true
Expand Down
Loading