Skip to content

Commit bf5291a

Browse files
Auto merge of #148146 - the8472:ci-use-extra-disk, r=<try>
CI: use alternative disks if available try-job: dist-x86_64-linux try-job: x86_64-gnu-aux try-job: dist-aarch64-linux try-job: aarch64-gnu-llvm-20-1
2 parents ba86c04 + 183f29b commit bf5291a

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

‎src/ci/docker/run.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ docker \
347347
--env DEPLOY \
348348
--env DEPLOY_ALT \
349349
--env CI \
350+
--env GIT_DISCOVERY_ACROSS_FILESYSTEM=1 \
350351
--env GITHUB_ACTIONS \
351352
--env GITHUB_REF \
352353
--env GITHUB_STEP_SUMMARY="/checkout/obj/${SUMMARY_FILE}" \

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ set -euo pipefail
44
# Free disk space on Linux GitHub action runners
55
# Script inspired by https://github.com/jlumbroso/free-disk-space
66

7+
8+
# we need ~50GB of space
9+
space_target_kb=$((50 * 1024 * 1024))
10+
11+
712
isX86() {
813
local arch
914
arch=$(uname -m)
@@ -247,12 +252,69 @@ cleanSwap() {
247252
free -h
248253
}
249254

255+
sufficientSpaceEarlyExit() {
256+
local available_space_kb=$(df -k . --output=avail | tail -n 1)
257+
258+
if [ "$available_space_kb" -ge "$space_target_kb" ]; then
259+
echo "Sufficient disk space available (${available_space_kb}KB >= ${space_target_kb}KB). Skipping cleanup."
260+
exit 0
261+
fi
262+
}
263+
264+
# Try to find a different drive to put our data on so we don't need to run cleanup.
265+
# The availability of the disks we're probing isn't guaranteed,
266+
# so this is opportunistic.
267+
checkAlternative() {
268+
local gha_alt_disk="/mnt"
269+
270+
local available_space_kb=$(df -k "$gha_alt_disk" --output=avail | tail -n 1)
271+
272+
# mount options that trade durability for performance
273+
# ignore-tidy-linelength
274+
local mntopts="defaults,discard,journal_async_commit,barrier=0,noauto_da_alloc,lazytime,data=writeback"
275+
276+
# GHA has a 2nd disk mounted at /mnt that is almost empty.
277+
# Check if it's a valid mountpoint and it has enough available space.
278+
if mountpoint "$gha_alt_disk" && [ "$available_space_kb" -ge "$space_target_kb" ]; then
279+
local blkdev=$(df -k "$gha_alt_disk" --output=source | tail -n 1)
280+
echo "Sufficient space available on $blkdev mounted at $gha_alt_disk"
281+
# see cleanSwap(), swapfile may be mounted under /mnt
282+
sudo swapoff -a || true
283+
284+
# unmount from original location
285+
sudo umount "$gha_alt_disk"
286+
287+
# remount under the obj dir which is used by docker scripts to write most
288+
# of our build output. And apply optimized mount options while we're at it.
289+
mkdir ./obj
290+
if ! sudo mount $blkdev ./obj -o $mntopts; then
291+
sudo dmesg | tail -n 20 # kernel log should have more details for mount failures
292+
echo "::warning::Failed to remount $blkdev to ./obj with options: $mntopts"
293+
return
294+
fi
295+
296+
# ensure current user can access everything.
297+
# later scripts assume they have recursive access to obj
298+
sudo chown -R "$USER":"$USER" ./obj
299+
300+
# Exit from this script to avoid wasting time removing disk space,
301+
# as we already have enough disk space in the alternative drive.
302+
exit 0
303+
fi
304+
}
305+
306+
307+
250308
# Display initial disk space stats
251309

252310
AVAILABLE_INITIAL=$(getAvailableSpace)
253311

254312
printDF "BEFORE CLEAN-UP:"
255313
echo ""
314+
315+
sufficientSpaceEarlyExit
316+
checkAlternative
317+
256318
execAndMeasureSpaceChange cleanPackages "Unused packages"
257319
execAndMeasureSpaceChange cleanDocker "Docker images"
258320
execAndMeasureSpaceChange cleanSwap "Swap storage"

0 commit comments

Comments
 (0)