diff --git a/.github/actions/ci/run-tests/action.yml b/.github/actions/ci/run-tests/action.yml index 75eb4c83f..ed020d284 100644 --- a/.github/actions/ci/run-tests/action.yml +++ b/.github/actions/ci/run-tests/action.yml @@ -16,28 +16,8 @@ runs: using: "composite" steps: - - name: 'Cleanup unused image dependencies (Linux)' - if: runner.os == 'Linux' - shell: bash - run: | - # This list is based on what the base image contains and - # may need to be adjusted as new software gets installed. - # Use the `du` command below to determine what can be - # uninstalled. - - rm -fR ~/.cargo - rm -fR ~/.rustup - rm -fR ~/.dotnet - sudo rm -fR /usr/share/swift - sudo rm -fR /opt/microsoft/msedge - sudo rm -fR /usr/local/.ghcup - sudo rm -fR /usr/lib/mono - sudo snap remove lxd - sudo snap remove core20 - sudo apt remove snapd - - df -h - # du -h -d 3 / + - name: Free disk space (Linux) + uses: ./.github/actions/host-cleanup-linux - name: Download Artifacts uses: actions/download-artifact@v4 diff --git a/.github/actions/host-cleanup-linux/action.yml b/.github/actions/host-cleanup-linux/action.yml new file mode 100644 index 000000000..1adfe9a95 --- /dev/null +++ b/.github/actions/host-cleanup-linux/action.yml @@ -0,0 +1,45 @@ +name: Host Cleanup (Linux) +description: Reclaims disk space on Linux CI agents by removing unused pre-installed software + +runs: + using: 'composite' + steps: + - name: Cleanup unused host dependencies + if: runner.os == 'Linux' + shell: bash + run: | + # This list is based on what the base image contains and + # may need to be adjusted as new software gets installed. + # Use the `du` command to determine what can be uninstalled. + + # Use sudo only when available and non-interactive (no password prompt) + if command -v sudo >/dev/null 2>&1 && sudo -n true >/dev/null 2>&1; then + SUDO="sudo -n" + else + SUDO="" + fi + + echo "Disk space before cleanup:" + df -h / + + rm -rf ~/.cargo ~/.rustup ~/.dotnet || true + + $SUDO rm -rf /usr/share/swift || true + $SUDO rm -rf /opt/microsoft/msedge || true + $SUDO rm -rf /usr/local/.ghcup || true + $SUDO rm -rf /usr/lib/mono || true + $SUDO rm -rf /usr/local/lib/android || true + $SUDO rm -rf /opt/ghc || true + $SUDO rm -rf /opt/hostedtoolcache/CodeQL || true + + if command -v snap >/dev/null 2>&1; then + timeout 60s $SUDO snap remove lxd || true + timeout 60s $SUDO snap remove core20 || true + fi + + if command -v apt-get >/dev/null 2>&1; then + DEBIAN_FRONTEND=noninteractive timeout 120s $SUDO apt-get purge -y snapd || true + fi + + echo "Disk space after cleanup:" + df -h / diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3724c8774..620ad2c70 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -63,6 +63,9 @@ jobs: fetch-depth: 0 ref: ${{ env.CheckoutRef }} + - name: Free disk space (Linux) + uses: ./.github/actions/host-cleanup-linux + - name: "Build Package" uses: ./.github/actions/ci/build-packages @@ -193,7 +196,7 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ env.CheckoutRef }} - + - name: "Run Tests" uses: ./.github/actions/ci/run-tests with: