forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
320 lines (288 loc) · 12.1 KB
/
Copy pathmobile-app-checks.yml
File metadata and controls
320 lines (288 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
name: Mobile App Checks
on:
push:
branches: main
pull_request:
branches: main
concurrency:
group: mobile-app-checks-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
changes:
name: Detect Changes
runs-on: ubuntu-latest
timeout-minutes: 20
outputs:
has_app_codegen: ${{ steps.changes.outputs.has_app_codegen }}
has_app_compile_smoke: ${{ steps.changes.outputs.has_app_compile_smoke }}
has_app_dart: ${{ steps.changes.outputs.has_app_dart }}
has_app_l10n: ${{ steps.changes.outputs.has_app_l10n }}
has_flutter_generated: ${{ steps.changes.outputs.has_flutter_generated }}
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
# Full history is required: detect-changes diffs against the merge
# base. blob:none keeps the commit graph but skips file contents,
# which is what made the unfiltered clone of this ~1.25GB repo take
# 7-13 minutes.
fetch-depth: 0
filter: blob:none
- name: Detect changed paths
id: changes
uses: ./.github/actions/detect-changes
generated-files:
name: Generated Files
runs-on: ubuntu-latest
timeout-minutes: 20
needs: changes
if: needs.changes.outputs.has_flutter_generated == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 1
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
# Match repo-checks.yml so dependency resolution cannot drift when
# the stable channel advances beyond the repository's lockfile.
flutter-version: 3.44.5
cache: true
# flutter-action already caches the SDK and ~/.pub-cache. build_runner's
# incremental state is not covered by it and is what makes codegen slow.
- name: Cache build_runner state
uses: actions/cache@v6
with:
path: app/.dart_tool/build
key: ${{ runner.os }}-flutter-buildrunner-${{ hashFiles('app/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-flutter-buildrunner-${{ hashFiles('app/pubspec.lock') }}-
${{ runner.os }}-flutter-buildrunner-
- name: Resolve Flutter dependencies
working-directory: app
run: flutter pub get
- name: Check Flutter generated code
if: needs.changes.outputs.has_app_codegen == 'true'
working-directory: app
run: |
dart run build_runner build --delete-conflicting-outputs
git diff --exit-code -- lib || {
echo "Generated Dart files are stale. Run: cd app && dart run build_runner build --delete-conflicting-outputs"
exit 1
}
if [ -n "$(git ls-files --others --exclude-standard -- lib)" ]; then
echo "Generated Dart files are stale; untracked generated files were produced:"
git ls-files --others --exclude-standard -- lib
exit 1
fi
- name: Check Flutter l10n
if: needs.changes.outputs.has_app_l10n == 'true'
working-directory: app
run: |
flutter gen-l10n
git diff --exit-code -- lib/l10n || {
echo "Generated localization files are stale. Run: cd app && flutter gen-l10n"
exit 1
}
if [ -n "$(git ls-files --others --exclude-standard -- lib/l10n)" ]; then
echo "Generated localization files are stale; untracked generated files were produced:"
git ls-files --others --exclude-standard -- lib/l10n
exit 1
fi
analyze-and-test:
name: Dart Analyze & Tests
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.has_app_dart == 'true'
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: 3.44.5
cache: true
- name: Cache build_runner state
uses: actions/cache@v6
with:
path: app/.dart_tool/build
key: ${{ runner.os }}-flutter-buildrunner-${{ hashFiles('app/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-flutter-buildrunner-${{ hashFiles('app/pubspec.lock') }}-
${{ runner.os }}-flutter-buildrunner-
- name: Resolve Flutter dependencies
working-directory: app
run: flutter pub get
# Also satisfies test.sh's generated-file prerequisites, so it skips its
# own pub get and build_runner run.
- name: Prepare Flutter dev compile inputs
working-directory: app
run: |
cp lib/firebase_options_local.dart lib/firebase_options_dev.dart
cp lib/firebase_options_local.dart lib/firebase_options_prod.dart
{
echo "API_BASE_URL="
echo "USE_WEB_AUTH=true"
echo "USE_AUTH_CUSTOM_TOKEN=true"
echo "STAGING_API_URL="
} > .dev.env
: > .env
- name: Generate Flutter code
working-directory: app
run: dart run build_runner build --delete-conflicting-outputs
- name: Run analyzer ratchet
working-directory: app
run: bash scripts/analyze_ratchet.sh
- name: Run Flutter tests
id: flutter_tests
working-directory: app
run: |
set -o pipefail
bash test.sh \
--reporter expanded \
--file-reporter "json:$GITHUB_WORKSPACE/flutter-test-results.json" \
2>&1 | tee "$GITHUB_WORKSPACE/flutter-test-output.log"
- name: Summarize failed Flutter tests
if: ${{ failure() && steps.flutter_tests.outcome == 'failure' }}
env:
FLUTTER_TEST_RESULTS: ${{ github.workspace }}/flutter-test-results.json
run: |
python3 - <<'PY'
import json
import os
from collections import defaultdict
from pathlib import Path
report = Path(os.environ['FLUTTER_TEST_RESULTS'])
summary = Path(os.environ['GITHUB_STEP_SUMMARY'])
tests = {}
errors = defaultdict(list)
failures = []
if report.exists():
for raw_line in report.read_text().splitlines():
try:
event = json.loads(raw_line)
except json.JSONDecodeError:
continue
event_type = event.get('type')
if event_type == 'testStart':
test = event.get('test', {})
tests[str(test.get('id'))] = test
elif event_type == 'error':
details = str(event.get('error', 'Unknown error'))
if event.get('stackTrace'):
details = f"{details}\n{event['stackTrace']}"
errors[str(event.get('testID'))].append(details)
elif event_type == 'testDone' and event.get('result') in {'failure', 'error'}:
failures.append(event)
with summary.open('a') as output:
output.write('## Flutter test diagnostics\n\n')
if not failures:
output.write(
'Flutter exited unsuccessfully but emitted no failed-test event. '
'Download the `flutter-test-diagnostics` artifact for the complete JSON stream and console log.\n'
)
for failure in failures:
test_id = str(failure.get('testID'))
test = tests.get(test_id, {})
name = test.get('name', f'Unknown test (id {test_id})')
output.write(f'### {name}\n\n')
details = '\n'.join(errors[test_id]).strip()
if details:
output.write('```text\n')
output.write(details[-6000:].replace('```', '``\\`'))
output.write('\n```\n\n')
PY
- name: Upload Flutter test diagnostics
if: ${{ failure() && steps.flutter_tests.outcome == 'failure' }}
uses: actions/upload-artifact@v7
with:
name: flutter-test-diagnostics
path: |
flutter-test-results.json
flutter-test-output.log
if-no-files-found: warn
android-compile-smoke:
name: Android Compile Smoke
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.has_app_compile_smoke == 'true'
timeout-minutes: 25
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 1
- name: Free runner disk space
# ubuntu-latest ships with ~14GB free; the Gradle build runs out of
# space during stripDebugSymbols. Remove unused preinstalled toolchains
# (keep /usr/local/lib/android — the build needs the Android SDK).
run: |
sudo rm -rf /usr/share/dotnet /usr/local/.ghcup /opt/hostedtoolcache/CodeQL \
/usr/local/share/boost /usr/local/share/chromium /usr/local/lib/node_modules
sudo docker image prune --all --force
df -h /
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: 3.44.5
cache: true
- name: Cache build_runner state
uses: actions/cache@v6
with:
path: app/.dart_tool/build
key: ${{ runner.os }}-flutter-buildrunner-${{ hashFiles('app/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-flutter-buildrunner-${{ hashFiles('app/pubspec.lock') }}-
${{ runner.os }}-flutter-buildrunner-
- name: Resolve Flutter dependencies
working-directory: app
run: flutter pub get
- name: Prepare Flutter dev compile inputs
working-directory: app
run: |
mkdir -p android/app/src/dev/ android/app/src/prod/
cp lib/firebase_options_local.dart lib/firebase_options_dev.dart
cp lib/firebase_options_local.dart lib/firebase_options_prod.dart
cp setup/prebuilt/google-services-local.json android/app/src/dev/google-services.json
cp setup/prebuilt/google-services-local.json android/app/src/prod/google-services.json
cp setup/prebuilt/key.properties android/key.properties
{
echo "API_BASE_URL="
echo "USE_WEB_AUTH=true"
echo "USE_AUTH_CUSTOM_TOKEN=true"
echo "STAGING_API_URL="
} > .dev.env
: > .env
- name: Generate Flutter code for compile smoke
working-directory: app
run: dart run build_runner build --delete-conflicting-outputs
- name: Setup Gradle for Flutter compile smoke
uses: gradle/actions/setup-gradle@v6
with:
# Default behaviour makes every non-default-branch run read-only AND
# never seeds the cache from main, so each PR paid a full cold
# assembleDevDebug ("Gradle User Home cache not found"). Stating the
# condition explicitly lets main runs write the cache that PRs read.
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
- name: Build Flutter Android dev debug APK and run native unit tests
working-directory: app
env:
# GitHub Actions sets CI=true; android/app/build.gradle reads Codemagic
# keystore env vars in that case even for debug APK builds.
CM_KEYSTORE_PATH: ${{ github.workspace }}/app/setup/prebuilt/debug.keystore
CM_KEYSTORE_PASSWORD: android
CM_KEY_ALIAS: androiddebugkey
CM_KEY_PASSWORD: android
# Single ABI: a compile smoke doesn't need arm + arm64 + x86_64 native
# libs, and the extra ABIs double disk usage during stripDebugSymbols.
run: |
flutter build apk --debug --flavor dev --target-platform android-arm64
cd android
# Tests run on the JVM; their Flutter compilation dependency must keep
# the APK's target selection to reuse its outputs instead of rebuilding all ABIs.
./gradlew :app:testDevDebugUnitTest -Ptarget-platform=android-arm64