|
| 1 | +#@doc |
| 2 | +# * PR gate for Mewbo Aura (apps/mewbo_aura): lints and unit-tests the `public` |
| 3 | +# distribution flavor ONLY. The `enterprise` flavor needs a private CA cert |
| 4 | +# that CI does not have (see android-release.yml) — never build/test it here. |
| 5 | +# |
| 6 | +# One job, not two: `:app:lintPublicDebug` and `:app:testPublicDebugUnitTest` |
| 7 | +# would otherwise provision JDK/SDK into the SAME persistent |
| 8 | +# `/opt/hostedtoolcache` volume in parallel, which is exactly the race |
| 9 | +# android-release.yml's concurrency comment documents (colliding unzip/mv → |
| 10 | +# mangled repo metadata → "Failed to find package"). Sequential steps in one |
| 11 | +# job reuse the already-provisioned toolcache for the second step for free. |
| 12 | + |
| 13 | +name: Android CI |
| 14 | + |
| 15 | +on: |
| 16 | + pull_request: |
| 17 | + paths: |
| 18 | + - "apps/mewbo_aura/**" |
| 19 | + - ".github/workflows/android-ci.yml" |
| 20 | + workflow_dispatch: |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: read |
| 24 | + |
| 25 | +# TWO axes, and the outer one is not about this PR at all. |
| 26 | +# |
| 27 | +# Per-PR cancellation is what you want for signal (a new commit supersedes the |
| 28 | +# old run), but it CANNOT be the concurrency group: every Android job on this |
| 29 | +# runner provisions into the same persistent /opt/hostedtoolcache volume, and |
| 30 | +# two concurrent provisioners race on the SDK dir — colliding unzip/mv, mangled |
| 31 | +# repo metadata, "Failed to find package". That is why android-release.yml |
| 32 | +# serializes on ONE global group rather than per-tag; a per-PR group here would |
| 33 | +# re-open the same race between two PRs, and between a PR and a release. |
| 34 | +# |
| 35 | +# So: share the release workflow's global group. Two Android runs never overlap. |
| 36 | +# cancel-in-progress stays FALSE — a PR run must never kill a release build. |
| 37 | +# |
| 38 | +# ⚠️ The cost is NOT "concurrent PRs queue" — it is sharper than that. A group |
| 39 | +# holds at most ONE pending run, so with a release building and PR A waiting, PR |
| 40 | +# B's arrival CANCELS A. A cancelled check is neither a pass nor a failure, so |
| 41 | +# nobody re-runs it; the PR simply has no Android signal until someone notices. |
| 42 | +# Accepted deliberately: PR volume here is low, and a missing gate you can see is |
| 43 | +# better than the toolcache race, which corrupts the SDK for every later run. |
| 44 | +# Re-push to re-trigger. If this starts biting, the fix is a per-PR group plus a |
| 45 | +# lockfile around the provisioning step only — NOT dropping the shared group. |
| 46 | +concurrency: |
| 47 | + group: android-toolcache |
| 48 | + cancel-in-progress: false |
| 49 | + |
| 50 | +defaults: |
| 51 | + run: |
| 52 | + working-directory: apps/mewbo_aura |
| 53 | + |
| 54 | +jobs: |
| 55 | + lint-and-test: |
| 56 | + name: Lint + unit test (public flavor) |
| 57 | + runs-on: ubuntu-22.04 |
| 58 | + timeout-minutes: 30 |
| 59 | + env: |
| 60 | + # Same persistent toolcache volume as android-release.yml, so a JDK/SDK |
| 61 | + # already provisioned by a release run (or an earlier CI run) is reused |
| 62 | + # instead of re-downloaded. |
| 63 | + ANDROID_HOME: /opt/hostedtoolcache/android-sdk |
| 64 | + GRADLE_USER_HOME: /opt/hostedtoolcache/gradle-home |
| 65 | + steps: |
| 66 | + - name: Checkout |
| 67 | + uses: actions/checkout@v6 |
| 68 | + |
| 69 | + - name: Provision Temurin JDK 21 (persistent toolcache, skipped when present) |
| 70 | + run: | |
| 71 | + set -euo pipefail |
| 72 | + JDK_DIR=/opt/hostedtoolcache/temurin-21-jdk |
| 73 | + if [ ! -x "$JDK_DIR/bin/java" ]; then |
| 74 | + curl -fsSL -o /tmp/jdk.tar.gz "https://api.adoptium.net/v3/binary/latest/21/ga/linux/x64/jdk/hotspot/normal/eclipse" |
| 75 | + mkdir -p "$JDK_DIR" |
| 76 | + tar -xzf /tmp/jdk.tar.gz -C "$JDK_DIR" --strip-components=1 |
| 77 | + rm /tmp/jdk.tar.gz |
| 78 | + fi |
| 79 | + echo "JAVA_HOME=$JDK_DIR" >> "$GITHUB_ENV" |
| 80 | + echo "$JDK_DIR/bin" >> "$GITHUB_PATH" |
| 81 | +
|
| 82 | + - name: Provision Android SDK (persistent toolcache, skipped when present) |
| 83 | + run: | |
| 84 | + set -euo pipefail |
| 85 | + if [ ! -d "$ANDROID_HOME/platforms/android-37.0" ] || [ ! -d "$ANDROID_HOME/build-tools/37.0.0" ]; then |
| 86 | + mkdir -p "$ANDROID_HOME/cmdline-tools" |
| 87 | + cd "$ANDROID_HOME/cmdline-tools" |
| 88 | + rm -rf latest cmdline-tools.zip |
| 89 | + curl -fsSL -o cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-13114758_latest.zip |
| 90 | + unzip -q cmdline-tools.zip |
| 91 | + mv cmdline-tools latest |
| 92 | + rm cmdline-tools.zip |
| 93 | + (yes || true) | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --sdk_root="$ANDROID_HOME" --licenses >/dev/null |
| 94 | + "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --sdk_root="$ANDROID_HOME" "platform-tools" "platforms;android-37.0" "build-tools;37.0.0" |
| 95 | + fi |
| 96 | +
|
| 97 | + # Both Gradle invocations below cap the JVM the same way android-release.yml |
| 98 | + # does, and for the same measured reason: the project's gradle.properties |
| 99 | + # asks for -Xmx4096m, while a job container here is capped at 2.5 GiB with |
| 100 | + # no swap, so the daemon is OOM-killed by construction and the build |
| 101 | + # reports only "Gradle build daemon disappeared unexpectedly". The jvmargs |
| 102 | + # value is quoted as ONE argument because it contains a space — unquoted, |
| 103 | + # Gradle receives `-XX:...` as its own flag and rejects it. |
| 104 | + - name: Lint (public flavor) |
| 105 | + run: | |
| 106 | + set -euo pipefail |
| 107 | + ./gradlew :app:lintPublicDebug \ |
| 108 | + "-Dorg.gradle.jvmargs=-Xmx1536m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \ |
| 109 | + -Dkotlin.compiler.execution.strategy=in-process \ |
| 110 | + -Dorg.gradle.caching=true \ |
| 111 | + --no-daemon --max-workers=2 |
| 112 | +
|
| 113 | + - name: Unit tests (public flavor; test sources are flavor-agnostic) |
| 114 | + run: | |
| 115 | + set -euo pipefail |
| 116 | + ./gradlew :app:testPublicDebugUnitTest \ |
| 117 | + "-Dorg.gradle.jvmargs=-Xmx1536m -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8" \ |
| 118 | + -Dkotlin.compiler.execution.strategy=in-process \ |
| 119 | + -Dorg.gradle.caching=true \ |
| 120 | + --no-daemon --max-workers=2 |
| 121 | +
|
| 122 | + - name: Upload lint report on failure |
| 123 | + if: failure() |
| 124 | + uses: actions/upload-artifact@v4 |
| 125 | + with: |
| 126 | + name: android-lint-report |
| 127 | + path: apps/mewbo_aura/app/build/reports/lint-results-publicDebug.html |
| 128 | + retention-days: 7 |
| 129 | + # warn, not ignore: a drifted report path must be visible, not a silent green. |
| 130 | + if-no-files-found: warn |
| 131 | + |
| 132 | + - name: Upload unit test results on failure |
| 133 | + if: failure() |
| 134 | + uses: actions/upload-artifact@v4 |
| 135 | + with: |
| 136 | + name: android-unit-test-results |
| 137 | + path: | |
| 138 | + apps/mewbo_aura/app/build/reports/tests/testPublicDebugUnitTest |
| 139 | + apps/mewbo_aura/app/build/test-results/testPublicDebugUnitTest |
| 140 | + retention-days: 7 |
| 141 | + # warn, not ignore: a drifted report path must be visible, not a silent green. |
| 142 | + if-no-files-found: warn |
0 commit comments