Skip to content

[experiment] ci: free more space in linux free runners #135834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4cd26a8
remove more stuff
marcoieni Jan 21, 2025
47bf534
no empty dirs
marcoieni Jan 21, 2025
2508423
remove more pkgs
marcoieni Jan 21, 2025
73b333f
don't remove swap storage
marcoieni Jan 21, 2025
2f85b99
more packages
marcoieni Jan 21, 2025
f88b7c2
print largest dirs
marcoieni Jan 21, 2025
56c826f
list snaps
marcoieni Jan 21, 2025
ed0b5cb
wip
marcoieni Jan 21, 2025
ae8f740
remove snaps
marcoieni Jan 21, 2025
893c928
sudo
marcoieni Jan 21, 2025
7b37cc4
uninstall r
marcoieni Jan 21, 2025
2d71268
more
marcoieni Jan 21, 2025
512fc8f
remove duplicate code
marcoieni Jan 21, 2025
9de37e3
sort
marcoieni Jan 21, 2025
e725d92
fix azure maybe
marcoieni Jan 21, 2025
3d7aa69
extract to function
marcoieni Jan 21, 2025
dd94875
fix azure maybe
marcoieni Jan 21, 2025
1bc4307
comment
marcoieni Jan 21, 2025
eddaf23
change order
marcoieni Jan 22, 2025
47d6ecb
fail
marcoieni Jan 22, 2025
a4016f5
undo
marcoieni Jan 22, 2025
8a9428f
try fix
marcoieni Jan 22, 2025
b27f12c
fix
marcoieni Jan 22, 2025
f1e36c1
fix
marcoieni Jan 22, 2025
c6eed90
remove libicu
marcoieni Jan 22, 2025
b21697a
revert
marcoieni Jan 22, 2025
569ebf3
libcpp
marcoieni Jan 22, 2025
971d07d
tmux
marcoieni Jan 22, 2025
ba6d1e1
revert libcpp
marcoieni Jan 22, 2025
3f8b1e0
jobs
marcoieni Jan 22, 2025
24838ae
fmt
marcoieni Jan 22, 2025
6ca1a50
keep node modules
marcoieni Jan 22, 2025
c23aa4c
Merge remote-tracking branch 'origin' into free-more-space
marcoieni Jan 27, 2025
6fe739a
hold npm
marcoieni Jan 27, 2025
dfde5f6
check if directory exists
marcoieni Jan 29, 2025
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
13 changes: 2 additions & 11 deletions src/ci/github-actions/jobs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,6 @@ pr:
- name: mingw-check-tidy
continue_on_error: true
<<: *job-linux-4c
- name: x86_64-gnu-llvm-18
env:
ENABLE_GCC_CODEGEN: "1"
# We are adding (temporarily) a dummy commit on the compiler
READ_ONLY_SRC: "0"
DOCKER_SCRIPT: x86_64-gnu-llvm.sh
<<: *job-linux-16c
- name: x86_64-gnu-tools
<<: *job-linux-16c

# Jobs that run when you perform a try build (@bors try)
# These jobs automatically inherit envs.try, to avoid repeating
Expand Down Expand Up @@ -182,7 +173,7 @@ auto:
<<: *job-linux-4c

- name: dist-powerpc64le-linux
<<: *job-linux-4c-largedisk
<<: *job-linux-4c

- name: dist-riscv64-linux
<<: *job-linux-4c
Expand Down Expand Up @@ -295,7 +286,7 @@ auto:
- name: x86_64-gnu-debug
# This seems to be needed because a full stage 2 build + run-make tests
# overwhelms the storage capacity of the standard 4c runner.
<<: *job-linux-4c-largedisk
<<: *job-linux-4c

- name: x86_64-gnu-distcheck
<<: *job-linux-8c
Expand Down
137 changes: 95 additions & 42 deletions src/ci/scripts/free-disk-space.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

# Free disk space on Linux GitHub action runners
# Script inspired by https://github.com/jlumbroso/free-disk-space
Expand Down Expand Up @@ -54,17 +55,6 @@ printDF() {
printSeparationLine "="
}

removeDir() {
dir=${1}

local before
before=$(getAvailableSpace)

sudo rm -rf "$dir" || true

printSavedSpace "$before" "$dir"
}

execAndMeasureSpaceChange() {
local operation=${1} # Function to execute
local title=${2}
Expand All @@ -79,39 +69,107 @@ execAndMeasureSpaceChange() {
# Remove large packages
# REF: https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh
cleanPackages() {
sudo apt-get -qq remove -y --fix-missing \
'^aspnetcore-.*' \
'^dotnet-.*' \
'^llvm-.*' \
'php.*' \
'^mongodb-.*' \
'^mysql-.*' \
'azure-cli' \
'google-chrome-stable' \
'firefox' \
'powershell' \
'mono-devel' \
'libgl1-mesa-dri' \
'google-cloud-sdk' \
'google-cloud-cli'
# Prevent npm from being removed.
# This command unfortunately also prevents npm from being updated,
# but it should be fine because we don't run `apt upgrade`.
sudo apt-mark hold npm

sudo apt-get -qq purge -y --autoremove --fix-missing \
'^aspnetcore-.*' \
'^dotnet-.*' \
'^java-*' \
'^libllvm.*' \
'^llvm.*' \
'^mongodb-.*' \
'^mysql-.*' \
'^r-base.*' \
'^vim.*' \
'azure-cli' \
'cpp-11' \
'firefox' \
'gcc-10' \
'gcc-11' \
'gcc-12' \
'gcc-9' \
'gcc' \
'google-chrome-stable' \
'google-cloud-cli' \
'google-cloud-sdk' \
'groff-base' \
'groff' \
'kubectl' \
'libgl1-mesa-dri' \
'libicu-dev' \
'mercurial-common' \
'microsoft-edge-stable' \
'mono-devel' \
'mono-llvm-tools' \
'php.*' \
'podman' \
'powershell' \
'python-babel-localedata' \
'python3-breezy' \
'skopeo' \
'snapd' \
'tmux'

sudo apt-get autoremove -y || echo "::warning::The command [sudo apt-get autoremove -y] failed"
sudo apt-get clean || echo "::warning::The command [sudo apt-get clean] failed failed"

echo "=> Installed packages sorted by size:"
# sort always fails because `head` stops reading stdin
dpkg-query -W --showformat='${Installed-Size} ${Package}\n' |
sort -nr 2>/dev/null | head -200 || true
}

# Remove Docker images
cleanDocker() {
echo "Removing the following docker images:"
echo "=> Removing the following docker images:"
sudo docker image ls
echo "Removing docker images..."
echo "=> Removing docker images..."
sudo docker image prune --all --force || true
}

# Remove Swap storage
cleanSwap() {
sudo swapoff -a || true
sudo rm -rf /mnt/swapfile || true
free -h
removeAllSnaps() {
# This won't remove the snaps `core` and `snapd`
sudo snap remove $(snap list | awk '!/^Name|^core|^snapd/ {print $1}')
}

removeUnusedDirectories() {
local dirs_to_remove=(
"/usr/lib/heroku/"
"/usr/local/lib/android"
"/usr/local/share/chromium"
"/usr/local/share/powershell"
"/usr/share/az_"*
"/usr/local/share/cmake-"*
"/usr/share/dotnet"
"/usr/share/icons/"
"/usr/share/miniconda/"
"/usr/share/swift"

# Environemnt variable set by GitHub Actions
"$AGENT_TOOLSDIRECTORY"

# Haskell runtime
"/opt/ghc"
"/usr/local/.ghcup"
)
local before

for dir in "${dirs_to_remove[@]}"; do
if [ ! -d "$dir" ]; then
echo "::warning::Directory $dir does not exist, skipping."
continue
fi
before=$(getAvailableSpace)
sudo rm -rf "$dir" || true
printSavedSpace "$before" "Removed $dir"
done

echo "=> largest directories:"
# sort always fails because `head` stops reading stdin
sudo du --max-depth=7 /* -h | sort -nr 2>/dev/null | head -1000 || true
}

# Display initial disk space stats
Expand All @@ -121,16 +179,11 @@ AVAILABLE_INITIAL=$(getAvailableSpace)
printDF "BEFORE CLEAN-UP:"
echo ""

removeDir /usr/local/lib/android
removeDir /usr/share/dotnet

# Haskell runtime
removeDir /opt/ghc
removeDir /usr/local/.ghcup

execAndMeasureSpaceChange cleanPackages "Large misc. packages"
execAndMeasureSpaceChange removeAllSnaps "Snaps"
execAndMeasureSpaceChange cleanPackages "Unused packages"
execAndMeasureSpaceChange cleanDocker "Docker images"
execAndMeasureSpaceChange cleanSwap "Swap storage"

removeUnusedDirectories

# Output saved space statistic
echo ""
Expand Down
Loading