From e35500fa2ffe1661e06bae114dabc7801ffaec56 Mon Sep 17 00:00:00 2001 From: be-nj Date: Wed, 26 Aug 2026 14:15:18 +0200 Subject: [PATCH] CI: cache the JDK, the SDK and Gradle on the runner host MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every push re-installed a JDK, re-downloaded the Android SDK and let Gradle fetch its distribution and every dependency again — roughly two of the three minutes a run took, spent on bytes that never change. The job now mounts a directory from the runner host at /cache and keeps the JDK, the SDK and GRADLE_USER_HOME there; both setup steps are skipped when what they install is already present. Tests and the APK build share one Gradle invocation instead of paying twice for JVM startup and configuration. Needs the mount whitelisted in the runner's valid_volumes (/etc/komodo/stacks/gitea/runner-cache/** on diana). Co-Authored-By: Claude Opus 5 (1M context) --- .github/workflows/build.yml | 62 ++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3e0cbd4..82f7a93 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,8 +11,19 @@ on: jobs: build: runs-on: ubuntu-latest + container: + image: docker.gitea.com/runner-images:ubuntu-latest + # A directory on the runner host, whitelisted in the runner's + # valid_volumes. Everything the job would otherwise download on every + # push — JDK, Android SDK, Gradle distribution and dependencies — + # lives here and survives the container. + options: -v /etc/komodo/stacks/gitea/runner-cache/castarr:/cache env: - ANDROID_SDK_ROOT: /opt/android-sdk + CACHE: /cache + JAVA_HOME: /cache/jdk17 + ANDROID_SDK_ROOT: /cache/android-sdk + GRADLE_USER_HOME: /cache/gradle + JDK_URL: https://api.adoptium.net/v3/binary/latest/17/ga/linux/x64/jdk/hotspot/normal/eclipse CMDLINE_TOOLS: https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip steps: - name: Checkout @@ -22,35 +33,42 @@ jobs: git fetch -q --depth 1 origin "${GITHUB_SHA}" git checkout -q FETCH_HEAD - - name: Install JDK + - name: JDK 17 run: | - apt-get update -qq - DEBIAN_FRONTEND=noninteractive apt-get install -y -qq openjdk-17-jdk-headless > /dev/null - java -version + if [ ! -x "$JAVA_HOME/bin/java" ]; then + echo "JDK nicht im Cache — einmalig herunterladen" + mkdir -p "$JAVA_HOME" + curl -sSL "$JDK_URL" | tar -xz -C "$JAVA_HOME" --strip-components=1 + fi + "$JAVA_HOME/bin/java" -version - - name: Install Android SDK + - name: Android SDK run: | - mkdir -p "$ANDROID_SDK_ROOT/cmdline-tools" - curl -sSL -o /tmp/tools.zip "$CMDLINE_TOOLS" - unzip -q /tmp/tools.zip -d "$ANDROID_SDK_ROOT/cmdline-tools" - mv "$ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools" "$ANDROID_SDK_ROOT/cmdline-tools/latest" - # Accept licences by writing the hashes: piping "yes" into - # sdkmanager dies of SIGPIPE (exit 141) under pipefail. - mkdir -p "$ANDROID_SDK_ROOT/licenses" - echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_SDK_ROOT/licenses/android-sdk-license" - echo "84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK_ROOT/licenses/android-sdk-preview-license" - "$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" \ - "platforms;android-35" "build-tools;35.0.0" "platform-tools" > /dev/null + if [ ! -d "$ANDROID_SDK_ROOT/platforms/android-35" ]; then + echo "SDK nicht im Cache — einmalig einrichten" + mkdir -p "$ANDROID_SDK_ROOT/cmdline-tools" + curl -sSL -o /tmp/tools.zip "$CMDLINE_TOOLS" + unzip -q -o /tmp/tools.zip -d "$ANDROID_SDK_ROOT/cmdline-tools" + rm -rf "$ANDROID_SDK_ROOT/cmdline-tools/latest" + mv "$ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools" "$ANDROID_SDK_ROOT/cmdline-tools/latest" + # Accept licences by writing the hashes: piping "yes" into + # sdkmanager dies of SIGPIPE (exit 141) under pipefail. + mkdir -p "$ANDROID_SDK_ROOT/licenses" + echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_SDK_ROOT/licenses/android-sdk-license" + echo "84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK_ROOT/licenses/android-sdk-preview-license" + JAVA_HOME="$JAVA_HOME" "$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager" \ + "platforms;android-35" "build-tools;35.0.0" "platform-tools" > /dev/null + fi echo "sdk.dir=$ANDROID_SDK_ROOT" > local.properties - - name: Unit tests - run: ./gradlew testDebugUnitTest --no-daemon --stacktrace - - - name: Build debug APK - run: ./gradlew assembleDebug --no-daemon --stacktrace + # One invocation, not two: a second --no-daemon run pays for another JVM + # start and another configuration phase to redo work it just did. + - name: Tests und Debug-APK + run: ./gradlew testDebugUnitTest assembleDebug --no-daemon --stacktrace - name: Summary if: always() run: | echo "APK:"; ls -la app/build/outputs/apk/debug/ 2>/dev/null || echo " (kein Build)" echo "Tests:"; ls tests/runs/junit/ 2>/dev/null || echo " (keine Reports)" + echo "Cache:"; du -sh "$CACHE"/* 2>/dev/null || echo " (leer)"