From 9c5f0c459fddde3cad344e17f6d726fb39bf161e Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 6 Nov 2026 09:41:18 -0800 Subject: [PATCH] fix(ci): measure the free space of a runner before deleting toolchains from it --- .github/actions/nix/action.yaml | 31 +++++++++++++++++++++------- .github/workflows/ci.yaml | 5 ++--- .github/workflows/sweeps.yaml | 4 ++-- .github/workflows/windows-guest.yaml | 1 - 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/.github/actions/nix/action.yaml b/.github/actions/nix/action.yaml index 95a06fcd..26c9bd7c 100644 --- a/.github/actions/nix/action.yaml +++ b/.github/actions/nix/action.yaml @@ -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 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 791767b9..79abe456 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 }} diff --git a/.github/workflows/sweeps.yaml b/.github/workflows/sweeps.yaml index d9b57c1c..7d3d03c8 100644 --- a/.github/workflows/sweeps.yaml +++ b/.github/workflows/sweeps.yaml @@ -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 }} diff --git a/.github/workflows/windows-guest.yaml b/.github/workflows/windows-guest.yaml index 5477fd46..3b13ba2d 100644 --- a/.github/workflows/windows-guest.yaml +++ b/.github/workflows/windows-guest.yaml @@ -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