Skip to content

Commit 6606937

Browse files
committed
Auto merge of rust-lang#135834 - marcoieni:free-more-space, r=<try>
[experiment] ci: free more space in linux free runners try-job: dist-powerpc64le-linux try-job: x86_64-gnu-debug
2 parents b2728d5 + 6ca1a50 commit 6606937

File tree

3 files changed

+189
-12
lines changed

3 files changed

+189
-12
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ jobs:
109109
# intensive jobs to run on free runners, which however also have
110110
# less disk space.
111111
- name: free up disk space
112-
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be
112+
run: src/ci/scripts/free-disk-space.sh
113113
if: matrix.free_disk
114114

115115
# Rust Log Analyzer can't currently detect the PR number of a GitHub

src/ci/github-actions/jobs.yml

+2-11
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@ pr:
100100
- name: mingw-check-tidy
101101
continue_on_error: true
102102
<<: *job-linux-4c
103-
- name: x86_64-gnu-llvm-18
104-
env:
105-
ENABLE_GCC_CODEGEN: "1"
106-
# We are adding (temporarily) a dummy commit on the compiler
107-
READ_ONLY_SRC: "0"
108-
DOCKER_SCRIPT: x86_64-gnu-llvm.sh
109-
<<: *job-linux-16c
110-
- name: x86_64-gnu-tools
111-
<<: *job-linux-16c
112103

113104
# Jobs that run when you perform a try build (@bors try)
114105
# These jobs automatically inherit envs.try, to avoid repeating
@@ -178,7 +169,7 @@ auto:
178169
<<: *job-linux-4c
179170

180171
- name: dist-powerpc64le-linux
181-
<<: *job-linux-4c-largedisk
172+
<<: *job-linux-4c
182173

183174
- name: dist-riscv64-linux
184175
<<: *job-linux-4c
@@ -291,7 +282,7 @@ auto:
291282
- name: x86_64-gnu-debug
292283
# This seems to be needed because a full stage 2 build + run-make tests
293284
# overwhelms the storage capacity of the standard 4c runner.
294-
<<: *job-linux-4c-largedisk
285+
<<: *job-linux-4c
295286

296287
- name: x86_64-gnu-distcheck
297288
<<: *job-linux-8c

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

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Free disk space on Linux GitHub action runners
5+
# Script inspired by https://github.com/jlumbroso/free-disk-space
6+
7+
# print a line of the specified character
8+
printSeparationLine() {
9+
for ((i = 0; i < 80; i++)); do
10+
printf "%s" "$1"
11+
done
12+
printf "\n"
13+
}
14+
15+
# compute available space
16+
# REF: https://unix.stackexchange.com/a/42049/60849
17+
# REF: https://stackoverflow.com/a/450821/408734
18+
getAvailableSpace() { echo $(df -a | awk 'NR > 1 {avail+=$4} END {print avail}'); }
19+
20+
# make Kb human readable (assume the input is Kb)
21+
# REF: https://unix.stackexchange.com/a/44087/60849
22+
formatByteCount() { echo $(numfmt --to=iec-i --suffix=B --padding=7 $1'000'); }
23+
24+
# macro to output saved space
25+
printSavedSpace() {
26+
# Disk space before the operation
27+
local before=${1}
28+
local title=${2:-}
29+
30+
local after
31+
after=$(getAvailableSpace)
32+
local saved=$((after - before))
33+
34+
echo ""
35+
printSeparationLine "*"
36+
if [ -n "${title}" ]; then
37+
echo "=> ${title}: Saved $(formatByteCount "$saved")"
38+
else
39+
echo "=> Saved $(formatByteCount "$saved")"
40+
fi
41+
printSeparationLine "*"
42+
echo ""
43+
}
44+
45+
# macro to print output of df with caption
46+
printDF() {
47+
local caption=${1}
48+
49+
printSeparationLine "="
50+
echo "${caption}"
51+
echo ""
52+
echo "$ df -h"
53+
echo ""
54+
df -h
55+
printSeparationLine "="
56+
}
57+
58+
execAndMeasureSpaceChange() {
59+
local operation=${1} # Function to execute
60+
local title=${2}
61+
62+
local before
63+
before=$(getAvailableSpace)
64+
$operation
65+
66+
printSavedSpace "$before" "$title"
67+
}
68+
69+
# Remove large packages
70+
# REF: https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh
71+
cleanPackages() {
72+
sudo apt-get -qq purge -y --autoremove --fix-missing \
73+
'^aspnetcore-.*' \
74+
'^dotnet-.*' \
75+
'^java-*' \
76+
'^libllvm.*' \
77+
'^llvm.*' \
78+
'^mongodb-.*' \
79+
'^mysql-.*' \
80+
'^r-base.*' \
81+
'^vim.*' \
82+
'azure-cli' \
83+
'cpp-11' \
84+
'firefox' \
85+
'gcc-10' \
86+
'gcc-11' \
87+
'gcc-12' \
88+
'gcc-9' \
89+
'gcc' \
90+
'google-chrome-stable' \
91+
'google-cloud-cli' \
92+
'google-cloud-sdk' \
93+
'groff-base' \
94+
'groff' \
95+
'kubectl' \
96+
'libgl1-mesa-dri' \
97+
'libicu-dev' \
98+
'mercurial-common' \
99+
'microsoft-edge-stable' \
100+
'mono-devel' \
101+
'mono-llvm-tools' \
102+
'php.*' \
103+
'podman' \
104+
'powershell' \
105+
'python-babel-localedata' \
106+
'python3-breezy' \
107+
'skopeo' \
108+
'snapd' \
109+
'tmux'
110+
111+
sudo apt-get autoremove -y || echo "::warning::The command [sudo apt-get autoremove -y] failed"
112+
sudo apt-get clean || echo "::warning::The command [sudo apt-get clean] failed failed"
113+
114+
echo "=> Installed packages sorted by size:"
115+
# sort always fails because `head` stops reading stdin
116+
dpkg-query -W --showformat='${Installed-Size} ${Package}\n' | \
117+
sort -nr 2>/dev/null | head -200 || true
118+
}
119+
120+
# Remove Docker images
121+
cleanDocker() {
122+
echo "=> Removing the following docker images:"
123+
sudo docker image ls
124+
echo "=> Removing docker images..."
125+
sudo docker image prune --all --force || true
126+
}
127+
128+
removeAllSnaps() {
129+
# This won't remove the snaps `core` and `snapd`
130+
sudo snap remove $(snap list | awk '!/^Name|^core|^snapd/ {print $1}')
131+
}
132+
133+
removeUnusedDirectories() {
134+
local dirs_to_remove=(
135+
"/usr/lib/heroku/"
136+
"/usr/local/lib/android"
137+
"/usr/local/share/chromium"
138+
"/usr/local/share/powershell"
139+
"/usr/share/az_"*
140+
"/usr/local/share/cmake-"*
141+
"/usr/share/dotnet"
142+
"/usr/share/icons/"
143+
"/usr/share/miniconda/"
144+
"/usr/share/swift"
145+
146+
# Environemnt variable set by GitHub Actions
147+
"$AGENT_TOOLSDIRECTORY"
148+
149+
# Haskell runtime
150+
"/opt/ghc"
151+
"/usr/local/.ghcup"
152+
)
153+
local before
154+
155+
for dir in "${dirs_to_remove[@]}"; do
156+
before=$(getAvailableSpace)
157+
sudo rm -rf "$dir" || true
158+
printSavedSpace "$before" "Removed $dir"
159+
done
160+
161+
echo "=> largest directories:"
162+
# sort always fails because `head` stops reading stdin
163+
sudo du --max-depth=7 /* -h | sort -nr 2>/dev/null | head -1000 || true
164+
}
165+
166+
# Display initial disk space stats
167+
168+
AVAILABLE_INITIAL=$(getAvailableSpace)
169+
170+
printDF "BEFORE CLEAN-UP:"
171+
echo ""
172+
173+
execAndMeasureSpaceChange removeAllSnaps "Snaps"
174+
execAndMeasureSpaceChange cleanPackages "Unused packages"
175+
execAndMeasureSpaceChange cleanDocker "Docker images"
176+
177+
removeUnusedDirectories
178+
179+
# Output saved space statistic
180+
echo ""
181+
printDF "AFTER CLEAN-UP:"
182+
183+
echo ""
184+
echo ""
185+
186+
printSavedSpace "$AVAILABLE_INITIAL" "Total saved"

0 commit comments

Comments
 (0)