Skip to content

Commit f3ba92f

Browse files
committed
Auto merge of rust-lang#136247 - marcoieni:free-more-space-ubuntu-24, r=<try>
[experiment] ci: free more space in ubuntu 24 free runners try-job: x86_64-gnu-debug
2 parents 61cc3e5 + cd97879 commit f3ba92f

File tree

2 files changed

+62
-41
lines changed

2 files changed

+62
-41
lines changed

src/ci/github-actions/jobs.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ runners:
55
env: { }
66

77
- &job-linux-4c
8-
os: ubuntu-22.04
8+
os: ubuntu-24.04
99
# Free some disk space to avoid running out of space during the build.
1010
free_disk: true
1111
<<: *base-job
@@ -50,7 +50,7 @@ runners:
5050
- &job-aarch64-linux
5151
# Free some disk space to avoid running out of space during the build.
5252
free_disk: true
53-
os: ubuntu-22.04-arm
53+
os: ubuntu-24.04-arm
5454

5555
- &job-aarch64-linux-8c
5656
os: ubuntu-22.04-arm64-8core-32gb
@@ -295,7 +295,7 @@ auto:
295295
- name: x86_64-gnu-debug
296296
# This seems to be needed because a full stage 2 build + run-make tests
297297
# overwhelms the storage capacity of the standard 4c runner.
298-
<<: *job-linux-4c-largedisk
298+
<<: *job-linux-4c
299299

300300
- name: x86_64-gnu-distcheck
301301
<<: *job-linux-8c

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

+59-38
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
# Free disk space on Linux GitHub action runners
45
# Script inspired by https://github.com/jlumbroso/free-disk-space
56

7+
# When updating to a new ubuntu version:
8+
# - Check that there are no docker images preinstalled with `docker image ls`
9+
# - Check that there are no big packages preinstalled that we aren't using
10+
611
# print a line of the specified character
712
printSeparationLine() {
813
for ((i = 0; i < 80; i++)); do
@@ -14,11 +19,15 @@ printSeparationLine() {
1419
# compute available space
1520
# REF: https://unix.stackexchange.com/a/42049/60849
1621
# REF: https://stackoverflow.com/a/450821/408734
17-
getAvailableSpace() { echo $(df -a | awk 'NR > 1 {avail+=$4} END {print avail}'); }
22+
getAvailableSpace() {
23+
df -a | awk 'NR > 1 {avail+=$4} END {print avail}'
24+
}
1825

1926
# make Kb human readable (assume the input is Kb)
2027
# REF: https://unix.stackexchange.com/a/44087/60849
21-
formatByteCount() { echo $(numfmt --to=iec-i --suffix=B --padding=7 $1'000'); }
28+
formatByteCount() {
29+
numfmt --to=iec-i --suffix=B --padding=7 "$1"'000'
30+
}
2231

2332
# macro to output saved space
2433
printSavedSpace() {
@@ -58,11 +67,30 @@ removeDir() {
5867
dir=${1}
5968

6069
local before
61-
before=$(getAvailableSpace)
62-
63-
sudo rm -rf "$dir" || true
70+
if [ ! -d "$dir" ]; then
71+
echo "::warning::Directory $dir does not exist, skipping."
72+
else
73+
before=$(getAvailableSpace)
74+
sudo rm -rf "$dir"
75+
printSavedSpace "$before" "Removed $dir"
76+
fi
77+
}
6478

65-
printSavedSpace "$before" "$dir"
79+
removeUnusedDirectories() {
80+
local dirs_to_remove=(
81+
"/usr/local/lib/android"
82+
# Haskell runtime
83+
"/usr/local/.ghcup"
84+
# Azure
85+
"/opt/az"
86+
"/etc/mysql"
87+
"/usr/share/php"
88+
"/etc/php/"
89+
)
90+
91+
for dir in "${dirs_to_remove[@]}"; do
92+
removeDir "$dir"
93+
done
6694
}
6795

6896
execAndMeasureSpaceChange() {
@@ -79,34 +107,33 @@ execAndMeasureSpaceChange() {
79107
# Remove large packages
80108
# REF: https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh
81109
cleanPackages() {
82-
sudo apt-get -qq remove -y --fix-missing \
83-
'^aspnetcore-.*' \
84-
'^dotnet-.*' \
85-
'^llvm-.*' \
86-
'php.*' \
87-
'^mongodb-.*' \
88-
'^mysql-.*' \
89-
'azure-cli' \
90-
'google-chrome-stable' \
91-
'firefox' \
92-
'powershell' \
93-
'mono-devel' \
94-
'libgl1-mesa-dri' \
95-
'google-cloud-sdk' \
96-
'google-cloud-cli'
110+
sudo apt-get purge -y --fix-missing \
111+
'^aspnetcore-.*' \
112+
'^dotnet-.*' \
113+
'^java-*' \
114+
'^libllvm.*' \
115+
'^llvm-.*' \
116+
'^mysql-.*' \
117+
'^vim.*' \
118+
'azure-cli' \
119+
'firefox' \
120+
'gcc' \
121+
'gcc-12' \
122+
'gcc-13' \
123+
'google-chrome-stable' \
124+
'google-cloud-cli' \
125+
'groff-base' \
126+
'kubectl' \
127+
'libgl1-mesa-dri' \
128+
'microsoft-edge-stable' \
129+
'php.*' \
130+
'powershell' \
131+
'snapd'
97132

98133
sudo apt-get autoremove -y || echo "::warning::The command [sudo apt-get autoremove -y] failed"
99134
sudo apt-get clean || echo "::warning::The command [sudo apt-get clean] failed failed"
100135
}
101136

102-
# Remove Docker images
103-
cleanDocker() {
104-
echo "Removing the following docker images:"
105-
sudo docker image ls
106-
echo "Removing docker images..."
107-
sudo docker image prune --all --force || true
108-
}
109-
110137
# Remove Swap storage
111138
cleanSwap() {
112139
sudo swapoff -a || true
@@ -121,17 +148,11 @@ AVAILABLE_INITIAL=$(getAvailableSpace)
121148
printDF "BEFORE CLEAN-UP:"
122149
echo ""
123150

124-
removeDir /usr/local/lib/android
125-
removeDir /usr/share/dotnet
126-
127-
# Haskell runtime
128-
removeDir /opt/ghc
129-
removeDir /usr/local/.ghcup
130-
131-
execAndMeasureSpaceChange cleanPackages "Large misc. packages"
132-
execAndMeasureSpaceChange cleanDocker "Docker images"
151+
execAndMeasureSpaceChange cleanPackages "Unused packages"
133152
execAndMeasureSpaceChange cleanSwap "Swap storage"
134153

154+
removeUnusedDirectories
155+
135156
# Output saved space statistic
136157
echo ""
137158
printDF "AFTER CLEAN-UP:"

0 commit comments

Comments
 (0)