Skip to content

Commit 6f621f2

Browse files
CI: Free up space on the github runner by deleting some tools we don't use (project-chip#32350)
Currently this deletes .NET tooling and parts of the Android SDK. Note that our Android CI builds bring their own Android SDK via the chip-build-android container, and do not rely on the copy that is installed in the GitHub Ubuntu image.
1 parent 177d875 commit 6f621f2

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

.github/actions/checkout-submodules-and-bootstrap/action.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ inputs:
1515
runs:
1616
using: "composite"
1717
steps:
18+
- name: Maximize runner disk
19+
uses: ./.github/actions/maximize-runner-disk
1820
- name: Dump disk info
1921
uses: ./.github/actions/dump-disk-info
2022
- name: Set git safe directory for local act runs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Maximize runner disk
2+
description: Free up disk space on the github runner
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Free up disk space on the github runner
7+
if: ${{ !env.ACT }}
8+
shell: bash
9+
run: |
10+
# maximize-runner-disk
11+
if [[ "$RUNNER_OS" == Linux ]]; then
12+
# Directories to prune to free up space. Candidates:
13+
# 1.6G /usr/share/dotnet
14+
# 1.1G /usr/local/lib/android/sdk/platforms
15+
# 1000M /usr/local/lib/android/sdk/build-tools
16+
# 8.9G /usr/local/lib/android/sdk
17+
# This list can be amended later to change the trade-off between the amount of
18+
# disk space freed up, and how long it takes to do so (deleting many files is slow).
19+
prune=(/usr/share/dotnet /usr/local/lib/android/sdk/platforms /usr/local/lib/android/sdk/build-tools)
20+
21+
if [[ "$UID" -eq 0 && -d /__w ]]; then
22+
root=/runner-root-volume
23+
if [[ ! -d "$root" ]]; then
24+
echo "Unable to maximize disk space, job is running inside a container and $root is not mounted"
25+
exit 0
26+
fi
27+
function sudo() { "$@"; } # we're already root (and sudo is probably unavailable)
28+
elif [[ "$UID" -ne 0 && "$RUNNER_ENVIRONMENT" == github-hosted ]]; then
29+
root=
30+
else
31+
echo "Unable to maximize disk space, unknown runner environment"
32+
exit 0
33+
fi
34+
35+
echo "Freeing up runner disk space on ${root:-/}"
36+
function avail() { df -k --output=avail "${root:-/}" | grep '^[0-9]*$'; }
37+
function now() { date '+%s'; }
38+
before="$(avail)" start="$(now)"
39+
for dir in "${prune[@]}"; do
40+
if [[ -d "${root}${dir}" ]]; then
41+
echo "- $dir"
42+
# du -sh -- "${root}${dir}"
43+
sudo rm -rf -- "${root}${dir}"
44+
else
45+
echo "- $dir (not found)"
46+
fi
47+
done
48+
after="$(avail)" end="$(now)"
49+
echo "Done, freed up $(( (after - before) / 1024 ))M of disk space in $(( end - start )) seconds."
50+
fi

.github/workflows/build.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
container:
4343
image: ghcr.io/project-chip/chip-build:35
4444
volumes:
45+
- "/:/runner-root-volume"
4546
- "/tmp/log_output:/tmp/test_logs"
4647
options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0
4748
net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1"
@@ -137,6 +138,7 @@ jobs:
137138
container:
138139
image: ghcr.io/project-chip/chip-build:35
139140
volumes:
141+
- "/:/runner-root-volume"
140142
- "/tmp/log_output:/tmp/test_logs"
141143
options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0
142144
net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1"
@@ -285,6 +287,7 @@ jobs:
285287
container:
286288
image: ghcr.io/project-chip/chip-build:35
287289
volumes:
290+
- "/:/runner-root-volume"
288291
- "/tmp/log_output:/tmp/test_logs"
289292
options: --sysctl "net.ipv6.conf.all.disable_ipv6=0
290293
net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1"
@@ -345,6 +348,7 @@ jobs:
345348
container:
346349
image: ghcr.io/project-chip/chip-build:35
347350
volumes:
351+
- "/:/runner-root-volume"
348352
- "/tmp/log_output:/tmp/test_logs"
349353
options: --sysctl "net.ipv6.conf.all.disable_ipv6=0
350354
net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1"
@@ -453,6 +457,7 @@ jobs:
453457
container:
454458
image: ghcr.io/project-chip/chip-build:35
455459
volumes:
460+
- "/:/runner-root-volume"
456461
- "/tmp/log_output:/tmp/test_logs"
457462
options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0
458463
net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1"

.github/workflows/smoketest-android.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
container:
4040
image: ghcr.io/project-chip/chip-build-android:35
4141
volumes:
42+
- "/:/runner-root-volume"
4243
- "/tmp/log_output:/tmp/test_logs"
4344

4445
steps:

.github/workflows/unit_integration_test.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
container:
4040
image: ghcr.io/project-chip/chip-build:35
4141
volumes:
42+
- "/:/runner-root-volume"
4243
- "/tmp/log_output:/tmp/test_logs"
4344
options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0 net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1"
4445

0 commit comments

Comments
 (0)