fix(ci): measure the free space of a runner before deleting toolchains from it

This commit is contained in:
LGUG2Z committed 2026-11-06 09:41:31 -08:00
1 parent 865ffcebda
commit 9c5f0c459f
4 files changed
+28 -13

No files matched your search

+24 -7
View File
@@ -24,9 +24,9 @@ inputs:
defer-no-kvm:
description: "With kvm, a host without a usable /dev/kvm does not fail the step: the output kvm is `missing`, every other step of the action is skipped, and the caller runs the job again on another host (.github/workflows/_vm.yaml). Off, that host fails the step"
default: "false"
free-disk:
description: Delete the toolchains of the hosted image that this repository does not use (about 25 GB)
default: "false"
disk-needed-gb:
description: "Free space on / that the job needs, in GB. The toolchains of the hosted image that this repository does not use (about 25 GB) are deleted only when less than this is free, and only until it is. With kvm, at least 40"
default: "0"
swap:
description: Add 16 GB of swap, for the jobs that evaluate NixOS systems (about 11 GB of memory at the peak)
default: "false"
@@ -109,13 +109,30 @@ runs:
exit 1
fi
# A Plasma guest is a closure of about 10 GB, and a hosted runner has little free space on /
# until the toolchains it ships with are gone.
# A Plasma guest is a closure of about 10 GB. A hosted runner usually has enough free space on / as it
# is, and deleting the toolchains it ships with takes from under a minute to eight, depending on the
# disk of the host that was drawn: so the space is measured first, and a directory is deleted only
# while the job would not fit, the largest first.
- name: Free disk space
if: steps.kvm.outputs.state != 'missing' && (inputs.free-disk == 'true' || inputs.kvm == 'true')
if: steps.kvm.outputs.state != 'missing' && (inputs.disk-needed-gb != '0' || inputs.kvm == 'true')
shell: bash
env:
NEEDED: ${{ inputs.disk-needed-gb }}
KVM: ${{ inputs.kvm }}
run: |
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL
needed=$NEEDED
if [ "$KVM" = true ] && [ "$needed" -lt 40 ]; then needed=40; fi
avail() { df --output=avail -BG / | tail -n 1 | tr -dc '0-9'; }
echo "free on /: $(avail) GB, needed: $needed GB"
for dir in /usr/local/lib/android /usr/share/dotnet /opt/ghc /opt/hostedtoolcache/CodeQL; do
if [ "$(avail)" -ge "$needed" ]; then
echo "enough space, nothing more is deleted"
break
fi
start=$SECONDS
sudo rm -rf "$dir"
echo "deleted $dir in $((SECONDS - start)) s, $(avail) GB free"
done
df -h /
- name: Add swap
+2 -3
View File
@@ -179,7 +179,6 @@ jobs:
- uses: actions/checkout@v6
- uses: ./.github/actions/nix
with:
free-disk: "true"
swap: "true"
cachix-cache: ${{ vars.CACHIX_CACHE }}
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
@@ -210,7 +209,7 @@ jobs:
- uses: actions/checkout@v6
- uses: ./.github/actions/nix
with:
free-disk: "true"
disk-needed-gb: "20"
cachix-cache: ${{ vars.CACHIX_CACHE }}
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
- run: nix build -L --no-link .#checkSets.${{ matrix.set }}
@@ -247,7 +246,7 @@ jobs:
- uses: actions/checkout@v6
- uses: ./.github/actions/nix
with:
free-disk: "true"
disk-needed-gb: "20"
cachix-cache: ${{ vars.CACHIX_CACHE }}
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
- run: nix build -L --no-link .#checkSets.${{ matrix.set }}
+2 -2
View File
@@ -72,7 +72,7 @@ jobs:
- uses: actions/checkout@v6
- uses: ./.github/actions/nix
with:
free-disk: "true"
disk-needed-gb: "30"
swap: "true"
cachix-cache: ${{ vars.CACHIX_CACHE }}
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
@@ -89,7 +89,7 @@ jobs:
- uses: actions/checkout@v6
- uses: ./.github/actions/nix
with:
free-disk: "true"
disk-needed-gb: "30"
swap: "true"
cachix-cache: ${{ vars.CACHIX_CACHE }}
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
-1
View File
@@ -26,7 +26,6 @@ jobs:
- uses: ./.github/actions/nix
with:
kvm: "true"
free-disk: "true"
cachix-cache: ${{ vars.CACHIX_CACHE }}
cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: Download the evaluation ISO