@@ -30,13 +30,19 @@ concurrency:
3030
3131jobs :
3232 emulator :
33- name : Build and test on the Android emulator
33+ name : Build and test on the Android emulator (shard ${{ matrix.shard }})
3434 if : github.repository == 'CopilotKit/OpenBot'
3535 runs-on : ubuntu-latest
3636 timeout-minutes : 40
37+ strategy :
38+ fail-fast : false
39+ matrix :
40+ shard : [1, 2]
3741 permissions :
3842 contents : read
3943 env :
44+ SHARD : ${{ matrix.shard }}
45+ SHARD_LABEL : " (shard ${{ matrix.shard }})"
4046 API_LEVEL : " 35"
4147 ARTIFACTS : ${{ github.workspace }}/artifacts
4248 PRIVATE_ARTIFACTS : ${{ github.workspace }}/private-artifacts
8995 - name : Build the web app and start the servers in the background
9096 run : nohup rn-shell/ci/start_servers.sh "$ARTIFACTS" > /dev/null 2>&1 &
9197
98+ - name : Key the APK on its sources from git's index
99+ id : apk-key
100+ run : |
101+ sum="$(git ls-files -s rn-shell/src rn-shell/modules rn-shell/plugins rn-shell/patches rn-shell/assets \
102+ rn-shell/app.config.ts rn-shell/index.ts rn-shell/package.json rn-shell/package-lock.json | sha256sum | cut -c1-40)"
103+ echo "key=rn-shell-android-apk-$sum" >> "$GITHUB_OUTPUT"
104+
105+ - name : Look for the built APK in the cache
106+ id : apk-cache
107+ uses : actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
108+ with :
109+ path : rn-shell/build/apk
110+ key : ${{ steps.apk-key.outputs.key }}
111+
92112 - uses : actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
113+ if : steps.apk-cache.outputs.cache-hit != 'true'
93114 with :
94115 node-version : " 22"
95116 cache : npm
@@ -101,6 +122,7 @@ jobs:
101122 java-version : " 17"
102123
103124 - name : Restore Gradle
125+ if : steps.apk-cache.outputs.cache-hit != 'true'
104126 id : gradle-cache
105127 uses : actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
106128 with :
@@ -111,6 +133,7 @@ jobs:
111133 restore-keys : rn-shell-gradle-
112134
113135 - name : Install, check and prebuild the test build
136+ if : steps.apk-cache.outputs.cache-hit != 'true'
114137 timeout-minutes : 6
115138 working-directory : rn-shell
116139 env :
@@ -125,6 +148,7 @@ jobs:
125148 printf '\norg.gradle.caching=true\n' >> android/gradle.properties
126149
127150 - name : Build the release APK with the test hooks (x86_64)
151+ if : steps.apk-cache.outputs.cache-hit != 'true'
128152 timeout-minutes : 20
129153 working-directory : rn-shell/android
130154 env :
@@ -134,23 +158,27 @@ jobs:
134158 ./gradlew --no-daemon :app:assembleRelease -PreactNativeArchitectures=x86_64 2>&1 \
135159 | tee "$ARTIFACTS/gradle.log" | grep -E "BUILD|error:|^e: |FAILURE" || true
136160 test -f app/build/outputs/apk/release/app-release.apk || { tail -n 120 "$ARTIFACTS/gradle.log"; exit 1; }
137- ls -la app/build/outputs/apk/release/
161+ mkdir -p ../build/apk
162+ cp app/build/outputs/apk/release/app-release.apk ../build/apk/
163+ (./gradlew --stop > /dev/null 2>&1) || true
164+ pkill -f KotlinCompileDaemon || true
138165
139166 # Saved even when a later step fails (actions/cache saves only after a successful job).
140167 - name : Save Gradle
141- if : always() && steps.gradle-cache.outputs.cache-hit != 'true'
168+ if : always() && steps.apk-cache.outputs.cache-hit != 'true' && steps. gradle-cache.outputs.cache-hit != 'true'
142169 uses : actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
143170 with :
144171 path : |
145172 ~/.gradle/caches
146173 ~/.gradle/wrapper
147174 key : ${{ steps.gradle-cache.outputs.cache-primary-key }}
148175
149- - name : Free the build's memory for the emulator
150- run : |
151- (cd rn-shell/android && ./gradlew --stop > /dev/null 2>&1) || true
152- pkill -f KotlinCompileDaemon || true
153- free -m
176+ - name : Save the built APK
177+ if : steps.apk-cache.outputs.cache-hit != 'true'
178+ uses : actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
179+ with :
180+ path : rn-shell/build/apk
181+ key : ${{ steps.apk-key.outputs.key }}
154182
155183 - name : Install Maestro
156184 timeout-minutes : 4
@@ -168,20 +196,20 @@ jobs:
168196 GPU_MODE=guest rn-shell/ci/emulator.sh prepare
169197 rn-shell/ci/emulator.sh describe
170198 rn-shell/ci/wait_for.sh "$ARTIFACTS/servers.ready" "$ARTIFACTS/servers.failed" 420 "$ARTIFACTS/servers.log"
171- adb install -r -g rn-shell/android/app/ build/outputs/ apk/release /app-release.apk
199+ adb install -r -g rn-shell/build/apk/app-release.apk
172200 adb shell pm list packages | grep ai.openbot
173201
174- - name : Run the mock suite
202+ - name : Run the mock suite (this shard)
175203 id : mock
176- timeout-minutes : 25
204+ timeout-minutes : 15
177205 run : |
178206 echo "$(date +%s) mock-suite" >> "$RUNNER_TEMP/timing"
179207 adb logcat -c || true
180208 nohup adb logcat -v time ReactNativeJS:V ReactNative:W chromium:W '*:S' > "$ARTIFACTS/logcat.txt" 2>&1 &
181- python3 rn-shell/ci/run_flows.py --platform android --suite mock --artifacts "$ARTIFACTS" --only "$ONLY"
209+ python3 rn-shell/ci/run_flows.py --platform android --suite mock --shard "$SHARD" -- artifacts "$ARTIFACTS" --only "$ONLY"
182210
183211 - name : Run the real-backend suite
184- if : always() && (steps.mock.conclusion == 'success' || steps.mock.conclusion == 'failure')
212+ if : always() && matrix.shard == 2 && (steps.mock.conclusion == 'success' || steps.mock.conclusion == 'failure')
185213 timeout-minutes : 12
186214 env :
187215 OPENBOT_SHELL_TEST_SESSION : ${{ secrets.OPENBOT_SHELL_TEST_SESSION }}
@@ -190,7 +218,7 @@ jobs:
190218 python3 rn-shell/ci/run_flows.py --platform android --suite real --artifacts "$ARTIFACTS" --private "$PRIVATE_ARTIFACTS" --only "$ONLY"
191219
192220 - name : Keep the built web app for the next run
193- if : always() && steps.web-cache.outputs.cache-hit != 'true' && hashFiles('app/dist/index.html') != ''
221+ if : always() && matrix.shard == 1 && steps.web-cache.outputs.cache-hit != 'true' && hashFiles('app/dist/index.html') != ''
194222 uses : actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
195223 with :
196224 path : app/dist
@@ -212,7 +240,7 @@ jobs:
212240 - uses : actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
213241 if : always()
214242 with :
215- name : rn-shell-android-${{ github.run_id }}
243+ name : rn-shell-android-${{ matrix.shard }}-${{ github.run_id }}
216244 path : artifacts/
217245 retention-days : 14
218246 if-no-files-found : warn
0 commit comments