Skip to content

Commit 0cb224d

Browse files
committed
ci: remove more unused files and directories in free runners
1 parent 8c61cd4 commit 0cb224d

File tree

1 file changed

+66
-21
lines changed

1 file changed

+66
-21
lines changed

src/ci/scripts/free-disk-space.sh

+66-21
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,75 @@ printDF() {
6969
printSeparationLine "="
7070
}
7171

72-
removeDir() {
73-
dir=${1}
74-
75-
local before
76-
if [ ! -d "$dir" ]; then
77-
echo "::warning::Directory $dir does not exist, skipping."
78-
else
79-
before=$(getAvailableSpace)
80-
sudo rm -rf "$dir"
81-
printSavedSpace "$before" "Removed $dir"
82-
fi
83-
}
84-
85-
removeUnusedDirectories() {
86-
local dirs_to_remove=(
72+
removeUnusedFilesAndDirs() {
73+
local to_remove=(
74+
"/etc/mysql"
75+
"/usr/local/aws-sam-cli"
76+
"/usr/local/doc/cmake"
77+
"/usr/local/julia"*
8778
"/usr/local/lib/android"
88-
"/usr/share/dotnet"
79+
"/usr/local/share/chromedriver-"*
80+
"/usr/local/share/chromium"
81+
"/usr/local/share/cmake-"*
82+
"/usr/local/share/edge_driver"
83+
"/usr/local/share/gecko_driver"
84+
"/usr/local/share/icons"
85+
"/usr/local/share/vim"
86+
"/usr/local/share/emacs"
87+
"/usr/local/share/powershell"
88+
"/usr/local/share/vcpkg"
89+
"/usr/share/apache-maven-"*
90+
"/usr/share/gradle-"*
91+
"/usr/share/java"
92+
"/usr/share/kotlinc"
93+
"/usr/share/miniconda"
94+
"/usr/share/php"
95+
"/usr/share/ri"
96+
"/usr/share/swift"
97+
98+
# binaries
99+
"/usr/local/bin/azcopy"
100+
"/usr/local/bin/bicep"
101+
"/usr/local/bin/ccmake"
102+
"/usr/local/bin/cmake-"*
103+
"/usr/local/bin/cmake"
104+
"/usr/local/bin/cpack"
105+
"/usr/local/bin/ctest"
106+
"/usr/local/bin/helm"
107+
"/usr/local/bin/kind"
108+
"/usr/local/bin/kustomize"
109+
"/usr/local/bin/minikube"
110+
"/usr/local/bin/packer"
111+
"/usr/local/bin/phpunit"
112+
"/usr/local/bin/pulumi-"*
113+
"/usr/local/bin/pulumi"
114+
"/usr/local/bin/stack"
89115

90116
# Haskell runtime
91117
"/usr/local/.ghcup"
118+
119+
# Azure
120+
"/opt/az"
121+
"/usr/share/az_"*
122+
123+
# Environment variable set by GitHub Actions
124+
"$AGENT_TOOLSDIRECTORY"
92125
)
93126

94-
for dir in "${dirs_to_remove[@]}"; do
95-
removeDir "$dir"
127+
# Filter existing files and directories because:
128+
# - We don't know if GitHub guarantees the existence of these files and
129+
# directories in the future and we don't want CI to fail in case
130+
# a file or directory is removed from the runners.
131+
# - Some files and directories don't exist on ARM runners because they have less software
132+
# installed than x86 runners.
133+
for element in "${to_remove[@]}"; do
134+
if [ ! -e "$element" ]; then
135+
echo "::warning::Directory or file $element does not exist, skipping."
136+
fi
96137
done
138+
139+
# Remove all files and directories at once to save time.
140+
sudo rm -rf "${to_remove[@]}"
97141
}
98142

99143
execAndMeasureSpaceChange() {
@@ -141,7 +185,9 @@ cleanPackages() {
141185
sudo apt-get clean || echo "::warning::The command [sudo apt-get clean] failed failed"
142186
}
143187

144-
# Remove Docker images
188+
# Remove Docker images.
189+
# Ubuntu 22 runners have docker images already installed.
190+
# They aren't present in ubuntu 24 runners.
145191
cleanDocker() {
146192
echo "=> Removing the following docker images:"
147193
sudo docker image ls
@@ -166,8 +212,7 @@ echo ""
166212
execAndMeasureSpaceChange cleanPackages "Unused packages"
167213
execAndMeasureSpaceChange cleanDocker "Docker images"
168214
execAndMeasureSpaceChange cleanSwap "Swap storage"
169-
170-
removeUnusedDirectories
215+
execAndMeasureSpaceChange removeUnusedFilesAndDirs "Unused files and directories"
171216

172217
# Output saved space statistic
173218
echo ""

0 commit comments

Comments
 (0)