Skip to content

Commit d54bcee

Browse files
authored
fix(ci): add Linux host disk cleanup for CI builds (#1736)
1 parent 06f4f80 commit d54bcee

6 files changed

Lines changed: 62 additions & 20 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Host Cleanup (Linux)
2+
description: Reclaims disk space on Linux CI agents by removing unused pre-installed software
3+
4+
runs:
5+
using: 'composite'
6+
steps:
7+
- name: Cleanup unused host dependencies
8+
if: runner.os == 'Linux'
9+
shell: bash
10+
run: bash "$GITHUB_WORKSPACE/build/workflow/scripts/host-cleanup-linux.sh"

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
fetch-depth: 0 # Required for gitversion
2727
submodules: true
2828

29+
- name: Free disk space (Linux)
30+
uses: ./.github/actions/host-cleanup-linux
31+
2932
- name: Setup dotnet 9.0.101
3033
uses: actions/[email protected]
3134
with:

‎build/workflow/build-wasm.yml‎

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,8 @@ jobs:
1616
fetchDepth: 0
1717
persistCredentials: true
1818

19-
- bash: |
20-
# This list is based on what the base image contains and
21-
# may need to be adjusted as new software gets installed.
22-
# Use the `du` command below to determine what can be
23-
# uninstalled.
24-
25-
rm -fR ~/.cargo
26-
rm -fR ~/.rustup
27-
rm -fR ~/.dotnet
28-
sudo rm -fR /usr/share/swift
29-
sudo rm -fR /opt/microsoft/msedge
30-
sudo rm -fR /usr/local/.ghcup
31-
sudo rm -fR /usr/lib/mono
32-
sudo snap remove lxd
33-
sudo snap remove core20
34-
sudo apt remove snapd
19+
- template: templates/host-cleanup-linux.yml
3520

36-
df -h
37-
# du -h -d 3 /
38-
displayName: 'Cleanup unused image dependencies (Linux)'
39-
condition: eq(variables['Agent.OS'], 'Linux')
4021
- task: UseDotNet@2
4122
retryCountOnTaskFailure: 3
4223
inputs:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
# Reclaims disk space on Linux CI agents by removing pre-installed
3+
# software that is not needed for the build.
4+
#
5+
# This list is based on what the base image contains and
6+
# may need to be adjusted as new software gets installed.
7+
# Use the `du` command to determine what can be uninstalled.
8+
9+
# Use sudo only when available and non-interactive (no password prompt)
10+
if command -v sudo >/dev/null 2>&1 && sudo -n true >/dev/null 2>&1; then
11+
SUDO="sudo -n"
12+
else
13+
SUDO=""
14+
fi
15+
16+
echo "Disk space before cleanup:"
17+
df -h /
18+
19+
rm -rf ~/.cargo ~/.rustup ~/.dotnet || true
20+
21+
$SUDO rm -rf /usr/share/swift || true
22+
$SUDO rm -rf /opt/microsoft/msedge || true
23+
$SUDO rm -rf /usr/local/.ghcup || true
24+
$SUDO rm -rf /usr/lib/mono || true
25+
$SUDO rm -rf /usr/local/lib/android || true
26+
$SUDO rm -rf /opt/ghc || true
27+
$SUDO rm -rf /opt/hostedtoolcache/CodeQL || true
28+
29+
if command -v snap >/dev/null 2>&1; then
30+
timeout 60s $SUDO snap remove lxd || true
31+
timeout 60s $SUDO snap remove core20 || true
32+
fi
33+
34+
if command -v apt-get >/dev/null 2>&1; then
35+
DEBIAN_FRONTEND=noninteractive timeout 120s $SUDO apt-get purge -y snapd || true
36+
fi
37+
38+
echo "Disk space after cleanup:"
39+
df -h /

‎build/workflow/stage-uitests-wasm.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ jobs:
77
vmImage: ubuntu-latest
88

99
steps:
10+
- template: templates/host-cleanup-linux.yml
11+
1012
- task: NodeTool@0
1113
inputs:
1214
versionSource: 'spec'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Reusable AzDO template: Cleanup unused dependencies on Linux CI agents.
2+
# Calls the shared host-cleanup-linux.sh script to avoid duplication with GitHub Actions.
3+
steps:
4+
- bash: |
5+
bash "$(Build.SourcesDirectory)/build/workflow/scripts/host-cleanup-linux.sh"
6+
displayName: Cleanup unused host dependencies
7+
condition: eq(variables['Agent.OS'], 'Linux')

0 commit comments

Comments
 (0)