CI: add Android runner disk cleanup and space guards

This commit is contained in:
bponders12-cell 2026-09-01 19:58:14 -04:00
parent 69bde34ac3
commit 432253b11f
1 changed files with 83 additions and 5 deletions

View File

@ -37,7 +37,6 @@ jobs:
with: with:
distribution: temurin distribution: temurin
java-version: ${{ env.JAVA_VERSION }} java-version: ${{ env.JAVA_VERSION }}
cache: gradle
- name: Set up Flutter - name: Set up Flutter
uses: subosito/flutter-action@v2 uses: subosito/flutter-action@v2
@ -46,6 +45,39 @@ jobs:
channel: stable channel: stable
cache: true cache: true
- name: Free runner disk space
shell: bash
run: |
set -euo pipefail
echo '--- Disk usage before cleanup ---'
df -h /
echo '--- Largest top-level directories ---'
sudo du -xhd1 / 2>/dev/null | sort -h | tail -n 15 || true
# GitHub-hosted Ubuntu images contain many preinstalled SDKs and
# toolchains that MotorSignal does not use. Remove only disposable
# software; keep Android SDK command-line tools, platform-tools,
# the active API/build-tools, CMake and NDK installations intact.
sudo rm -rf /usr/share/dotnet \
/usr/local/share/powershell \
/opt/ghc \
/usr/local/.ghcup \
/usr/local/lib/android/sdk/emulator \
/usr/local/lib/android/sdk/system-images
sudo apt-get clean || true
sudo rm -rf /var/lib/apt/lists/*
docker system prune -af --volumes 2>/dev/null || true
echo '--- Disk usage after cleanup ---'
df -h /
AVAILABLE_KB="$(df --output=avail / | tail -n 1 | tr -d ' ')"
MIN_AVAILABLE_KB=$((5 * 1024 * 1024))
if [ "$AVAILABLE_KB" -lt "$MIN_AVAILABLE_KB" ]; then
echo "ERROR: less than 5 GiB remains on the runner after cleanup."
exit 1
fi
- name: Create Flutter local.properties - name: Create Flutter local.properties
shell: bash shell: bash
run: | run: |
@ -86,6 +118,7 @@ jobs:
flutter doctor -v flutter doctor -v
java -version java -version
sdkmanager --list_installed | grep -E 'platforms;android-37|build-tools;37|platform-tools' || true sdkmanager --list_installed | grep -E 'platforms;android-37|build-tools;37|platform-tools' || true
df -h /
- name: Get dependencies - name: Get dependencies
run: flutter pub get run: flutter pub get
@ -97,7 +130,12 @@ jobs:
run: flutter test run: flutter test
- name: Build debug APK - name: Build debug APK
run: flutter build apk --debug shell: bash
run: |
set -euo pipefail
df -h /
flutter build apk --debug
df -h /
- name: Verify debug APK - name: Verify debug APK
shell: bash shell: bash
@ -135,7 +173,6 @@ jobs:
with: with:
distribution: temurin distribution: temurin
java-version: ${{ env.JAVA_VERSION }} java-version: ${{ env.JAVA_VERSION }}
cache: gradle
- name: Set up Flutter - name: Set up Flutter
uses: subosito/flutter-action@v2 uses: subosito/flutter-action@v2
@ -144,6 +181,37 @@ jobs:
channel: stable channel: stable
cache: true cache: true
- name: Free runner disk space
shell: bash
run: |
set -euo pipefail
echo '--- Disk usage before cleanup ---'
df -h /
echo '--- Largest top-level directories ---'
sudo du -xhd1 / 2>/dev/null | sort -h | tail -n 15 || true
# Keep only software relevant to the Android build. Android SDK
# command-line tools, active SDK/build-tools, CMake and NDK are kept.
sudo rm -rf /usr/share/dotnet \
/usr/local/share/powershell \
/opt/ghc \
/usr/local/.ghcup \
/usr/local/lib/android/sdk/emulator \
/usr/local/lib/android/sdk/system-images
sudo apt-get clean || true
sudo rm -rf /var/lib/apt/lists/*
docker system prune -af --volumes 2>/dev/null || true
echo '--- Disk usage after cleanup ---'
df -h /
AVAILABLE_KB="$(df --output=avail / | tail -n 1 | tr -d ' ')"
MIN_AVAILABLE_KB=$((5 * 1024 * 1024))
if [ "$AVAILABLE_KB" -lt "$MIN_AVAILABLE_KB" ]; then
echo "ERROR: less than 5 GiB remains on the runner after cleanup."
exit 1
fi
- name: Create Flutter local.properties - name: Create Flutter local.properties
shell: bash shell: bash
run: | run: |
@ -223,10 +291,20 @@ jobs:
-alias "$KEY_ALIAS" >/dev/null -alias "$KEY_ALIAS" >/dev/null
- name: Build release APK - name: Build release APK
run: flutter build apk --release shell: bash
run: |
set -euo pipefail
df -h /
flutter build apk --release
df -h /
- name: Build release App Bundle - name: Build release App Bundle
run: flutter build appbundle --release shell: bash
run: |
set -euo pipefail
df -h /
flutter build appbundle --release
df -h /
- name: Verify release artifacts and signatures - name: Verify release artifacts and signatures
shell: bash shell: bash