Repository navigation
Expand file tree
/
Copy pathmorrowbyte-android-native-test.yml
More file actions
311 lines (295 loc) · 17.3 KB
/
Copy pathmorrowbyte-android-native-test.yml
File metadata and controls
311 lines (295 loc) · 17.3 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
name: Android updater native x86_64 test
run-name: Android updater x86_64 test only · source 78c21571
on:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: android55-x86-native-test
cancel-in-progress: false
jobs:
build_android_test:
name: Build .55 x86_64 native test APK
runs-on: [self-hosted, "${{ vars.MORROWBYTE_LINUX_RUNNER || 'morrowbyte-linux' }}"]
timeout-minutes: 60
outputs:
apk_sha256: ${{ steps.apk.outputs.apk_sha256 }}
receipt_sha256: ${{ steps.apk.outputs.receipt_sha256 }}
build_attempt: ${{ steps.apk.outputs.build_attempt }}
env:
APP_VARIANT: production
MOBILE_VERSION_POLICY: appVersion
T3CODE_MOBILE_VERSION: 0.1.2-nightly.20261018.55
MORROWBYTE_ANDROID_VERSION_CODE: "55"
ANDROID_BUILD_TOOLS: "36.0.0"
CI: "1"
NODE_OPTIONS: --max-old-space-size=2560
CMAKE_BUILD_PARALLEL_LEVEL: "2"
steps:
- name: Require exact private updater candidate dispatch
env:
REQUESTED_REF: ${{ github.ref }}
REQUESTED_REPOSITORY: ${{ github.repository }}
run: |
test "$REQUESTED_REPOSITORY" = morrowbyte/t3code
test "$REQUESTED_REF" = refs/heads/fix/android-background-voice-transcript-20261019
- name: Bind runner-local signing path
run: printf 'MORROWBYTE_ANDROID_KEYSTORE_PATH=%s/morrowbyte-signing/morrowbyte-release.p12\n' "$RUNNER_TEMP" >> "$GITHUB_ENV"
- name: Checkout exact updater source
uses: actions/checkout@v4
with:
ref: 78c21571bb5adf41643ef7d8924ee6a4dc8abfe9
fetch-depth: 1
- name: Setup Vite+
uses: voidzero-dev/setup-vp@250f29ce396baf5e8f24498e17c0dfdebabc26eb # v1
with:
node-version-file: package.json
cache: true
run-install: false
- name: Install frozen mobile dependency closure
run: vp install --frozen-lockfile --filter=@t3tools/mobile... --filter=@t3tools/scripts...
- name: Setup Java
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "21"
- name: Setup Android build and verification tools
uses: android-actions/setup-android@v4
with:
packages: "platform-tools build-tools;36.0.0"
log-accepted-android-sdk-licenses: false
- name: Setup Gradle cache
uses: gradle/actions/setup-gradle@v5
- name: Bind source and verify standalone fork configuration
working-directory: apps/mobile
env:
SOURCE_SHA: 78c21571bb5adf41643ef7d8924ee6a4dc8abfe9
NODE_ENV: production
run: |
set -euo pipefail
test "$(git rev-parse HEAD)" = "$SOURCE_SHA"
test "$(sha256sum ../../pnpm-lock.yaml | cut -d' ' -f1)" = 6b7540e69f174e62461b68a2918fcf498461dccd3cdd6edd94877f9f1d1e8484
node node_modules/expo/bin/cli config --type public --json > "$RUNNER_TEMP/morrowbyte-config.json"
python3 - <<'PYCONFIG'
import json, os
from pathlib import Path
config = json.loads((Path(os.environ['RUNNER_TEMP']) / 'morrowbyte-config.json').read_text())
assert config['name'] == 'Crew'
assert config['scheme'] == 'morrowbyte'
assert config['android']['package'] == 'com.morrowbyte.t3code'
assert config['version'] == os.environ['T3CODE_MOBILE_VERSION']
assert config['android']['versionCode'] == int(os.environ['MORROWBYTE_ANDROID_VERSION_CODE'])
assert config['updates']['enabled'] is False and not config['updates'].get('url')
assert not config.get('owner'), 'Standalone Android must not have an EAS owner.'
# Sharing/widgets add local iOS extension metadata without binding an EAS project.
eas_metadata = config.get('extra', {}).get('eas', {})
for key in ('build', 'experimental', 'ios', 'appExtensions'):
assert isinstance(eas_metadata, dict) and set(eas_metadata) <= {key}, 'Unexpected EAS account/project configuration.'
eas_metadata = eas_metadata.get(key, [] if key == 'appExtensions' else {})
assert isinstance(eas_metadata, list), 'Unexpected EAS extension metadata.'
PYCONFIG
- name: Generate Android release project
working-directory: apps/mobile
env:
NODE_ENV: production
run: node node_modules/expo/bin/cli prebuild --platform android --no-install --clean
- name: Bound Metro workers and fingerprint the generated test project
working-directory: apps/mobile
env:
NODE_ENV: production
run: |
set -euo pipefail
python3 - <<'PYPACKAGER'
import hashlib
from pathlib import Path
gradle = Path('android/app/build.gradle')
text = gradle.read_text()
assert text.count('react {\n') == 1
gradle.write_text(text.replace('react {\n', 'react {\n extraPackagerArgs = ["--max-workers", "2"]\n', 1))
assert 'android.enableMinifyInReleaseBuilds=true' in Path('android/gradle.properties').read_text().splitlines()
verifier = Path('modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/ApkUpdateVerifier.kt')
assert hashlib.sha256(verifier.read_bytes()).hexdigest() == '47c60f4766a180485bc752c4637a9cbeec5ad983bfb84e2d21dc69a5519eb9df'
PYPACKAGER
node <<'JSFINGERPRINT'
const fs = require('node:fs');
const { createRequire } = require('node:module');
const mobileRequire = createRequire(process.cwd() + '/package.json');
const fingerprint = createRequire(mobileRequire.resolve('expo-updates/package.json'))('@expo/fingerprint');
fingerprint.createFingerprintAsync(process.cwd(), { platforms: ['android'] }).then(value => {
if (!value.hash || !value.sources.some(source => source.filePath === 'modules/t3-native-controls/android')) {
throw new Error('Native controls missing from the generated test fingerprint');
}
fs.writeFileSync(process.env.RUNNER_TEMP + '/morrowbyte-fingerprint.json', JSON.stringify(value, null, 2));
console.log(JSON.stringify({ hash: value.hash, sources: value.sources.length }));
}).catch(error => { console.error(error); process.exitCode = 1; });
JSFINGERPRINT
- name: Materialize own release keystore
env:
MORROWBYTE_ANDROID_KEYSTORE_BASE64: ${{ secrets.MORROWBYTE_ANDROID_KEYSTORE_BASE64 }}
run: |
set -euo pipefail
umask 077
python3 - <<'PYKEY'
import base64, os
from pathlib import Path
target = Path(os.environ['MORROWBYTE_ANDROID_KEYSTORE_PATH'])
target.parent.mkdir(mode=0o700, exist_ok=True)
encoded = ''.join(os.environ['MORROWBYTE_ANDROID_KEYSTORE_BASE64'].split())
assert encoded, 'Own Android signing keystore is missing.'
target.write_bytes(base64.b64decode(encoded, validate=True))
target.chmod(0o600)
PYKEY
- name: Build signed standalone x86_64 test APK once
working-directory: apps/mobile/android
env:
NODE_ENV: production
MORROWBYTE_ANDROID_STORE_PASSWORD: ${{ secrets.MORROWBYTE_ANDROID_STORE_PASSWORD }}
MORROWBYTE_ANDROID_KEY_ALIAS: ${{ secrets.MORROWBYTE_ANDROID_KEY_ALIAS }}
MORROWBYTE_ANDROID_KEY_PASSWORD: ${{ secrets.MORROWBYTE_ANDROID_KEY_PASSWORD }}
run: |
set -euo pipefail
test -s "$MORROWBYTE_ANDROID_KEYSTORE_PATH"
test -n "$MORROWBYTE_ANDROID_STORE_PASSWORD"
test "$MORROWBYTE_ANDROID_KEY_ALIAS" = morrowbyte-release
test -n "$MORROWBYTE_ANDROID_KEY_PASSWORD"
./gradlew :app:dependencies --configuration releaseRuntimeClasspath --no-daemon --no-configuration-cache \
--max-workers=2 -Dorg.gradle.parallel=false -PreactNativeArchitectures=x86_64 \
-Dorg.gradle.jvmargs='-Xmx4096m -XX:MaxMetaspaceSize=1024m -XX:ActiveProcessorCount=4' \
> "$RUNNER_TEMP/morrowbyte-android-dependencies.txt"
./gradlew :app:assembleRelease --no-daemon --no-configuration-cache --max-workers=2 \
-Dorg.gradle.parallel=false -PreactNativeArchitectures=x86_64 \
-Dorg.gradle.jvmargs='-Xmx4096m -XX:MaxMetaspaceSize=1024m -XX:ActiveProcessorCount=4' \
-Pkotlin.daemon.jvmargs=-Xmx1024m
- id: apk
name: Verify APK signature, embedded bundle, identity and 16KB native alignment
env:
SOURCE_SHA: 78c21571bb5adf41643ef7d8924ee6a4dc8abfe9
run: |
set -euo pipefail
python3 - <<'PYAPK'
import hashlib, json, os, re, shutil, struct, subprocess, zipfile
from pathlib import Path
digest = lambda p: hashlib.sha256(p.read_bytes()).hexdigest()
source = os.environ['SOURCE_SHA']
assert subprocess.check_output(['git', 'rev-parse', 'HEAD'], text=True).strip() == source
version = os.environ['T3CODE_MOBILE_VERSION']
assert re.fullmatch(r'[0-9A-Za-z][0-9A-Za-z.+-]*', version)
code = int(os.environ['MORROWBYTE_ANDROID_VERSION_CODE'])
assert 0 < code <= 2100000000
expected_cert = '34a33c2541544bc4a96e359a33e9f71aaa449ee9a0cd725c2469b65b057aa2b2'
sdk = Path(os.environ['ANDROID_HOME']) / 'build-tools' / os.environ['ANDROID_BUILD_TOOLS']
built = Path('apps/mobile/android/app/build/outputs/apk/release')
candidates = list(built.glob('*.apk'))
assert len(candidates) == 1, 'Expected one standalone release APK.'
apk = candidates[0]
signature = subprocess.check_output([str(sdk / 'apksigner'), 'verify', '-Werr', '--verbose', '--print-certs', str(apk)], text=True)
certificates = re.findall(r'^Signer #\d+ certificate SHA-256 digest: ([0-9a-fA-F:]+)$', signature, re.M)
assert len(certificates) == 1 and certificates[0].replace(':', '').lower() == expected_cert
subprocess.run([str(sdk / 'zipalign'), '-c', '-P', '16', '-v', '4', str(apk)], check=True, stdout=subprocess.DEVNULL)
badging = subprocess.check_output([str(sdk / 'aapt'), 'dump', 'badging', str(apk)], text=True)
identity = re.search(r"^package: name='([^']+)' versionCode='([^']+)' versionName='([^']+)'", badging, re.M)
assert identity and identity.groups() == ('com.morrowbyte.t3code', str(code), version)
assert "application-label:'Crew'" in badging and 'application-debuggable' not in badging
for permission in ['INTERNET', 'RECORD_AUDIO', 'MODIFY_AUDIO_SETTINGS']:
assert "name='android.permission." + permission + "'" in badging
with zipfile.ZipFile(apk) as archive:
names = archive.namelist()
bundle = 'assets/index.android.bundle'
assert bundle in names and archive.getinfo(bundle).file_size > 10000
libraries = [name for name in names if name.startswith('lib/') and name.endswith('.so')]
assert libraries and {name.split('/')[1] for name in libraries} == {'x86_64'}
assert any('hermes' in name for name in libraries)
assert any('jingle_peerconnection' in name or 'webrtc' in name for name in libraries)
for name in libraries:
data = archive.read(name)
assert data[:6] == b'\x7fELF\x02\x01', name
assert struct.unpack_from('<H', data, 18)[0] == 62, name
offset = struct.unpack_from('<Q', data, 32)[0]
entry_size, entry_count = struct.unpack_from('<HH', data, 54)
loads = 0
for index in range(entry_count):
header = offset + index * entry_size
if struct.unpack_from('<I', data, header)[0] != 1:
continue
loads += 1
file_offset, address = struct.unpack_from('<QQ', data, header + 8)
alignment = struct.unpack_from('<Q', data, header + 48)[0]
assert alignment >= 16384 and file_offset % 16384 == address % 16384, name
assert loads > 0, name
defined = set()
for name in [name for name in names if re.fullmatch(r'classes\d*\.dex', name)]:
data = archive.read(name)
strings_count, strings_offset, types_count, types_offset = struct.unpack_from('<IIII', data, 56)
classes_count, classes_offset = struct.unpack_from('<II', data, 96)
strings = []
for index in range(strings_count):
offset = struct.unpack_from('<I', data, strings_offset + index * 4)[0]
while data[offset] & 128:
offset += 1
offset += 1
strings.append(data[offset:data.index(0, offset)].decode('utf-8', errors='replace'))
types = struct.unpack_from('<' + str(types_count) + 'I', data, types_offset)
defined.update(strings[types[struct.unpack_from('<I', data, classes_offset + index * 32)[0]]] for index in range(classes_count))
assert {'Lorg/jni_zero/JniZero;', 'Lorg/jni_zero/CommonApis;', 'Lcom/morrowbyte/t3code/MainActivity;'} <= defined
bundle_sha = hashlib.sha256(archive.read(bundle)).hexdigest()
generated_bundle = Path('apps/mobile/android/app/build/generated/assets/react/release/index.android.bundle')
assert generated_bundle.is_file() and digest(generated_bundle) == bundle_sha, 'APK must embed the bundle generated from the pinned updater source.'
mapping = Path('apps/mobile/android/app/build/outputs/mapping/release/mapping.txt')
assert mapping.is_file() and mapping.stat().st_size > 0, 'Minified release mapping is missing.'
fingerprint = json.loads((Path(os.environ['RUNNER_TEMP']) / 'morrowbyte-fingerprint.json').read_text())
output = Path('release-android')
output.mkdir()
name = f'Morrowbyte-{version}-android-test-x86_64.apk'
target = output / name
shutil.copyfile(apk, target)
assert digest(target) == digest(apk)
apk_sha = digest(target)
(output / (name + '.sha256')).write_text(f'{apk_sha} {name}\n')
receipt = {
'schemaVersion': 1, 'testOnly': True, 'shippingArtifact': False,
'buildMode': 'release', 'minificationUnchanged': True, 'source': source,
'nativeFingerprint': fingerprint['hash'], 'nativeFingerprintSourceCount': len(fingerprint['sources']),
'apkVerifierSha256': digest(Path('apps/mobile/modules/t3-native-controls/android/src/main/java/expo/modules/t3nativecontrols/ApkUpdateVerifier.kt')),
'generatedAppGradleSha256': digest(Path('apps/mobile/android/app/build.gradle')),
'resourceProfile': {'metroWorkers': 2, 'gradleWorkers': 2, 'gradleHeapMiB': 4096, 'kotlinHeapMiB': 1024, 'nodeOldSpaceMiB': 2560},
'lockSha256': digest(Path('pnpm-lock.yaml')),
'run': os.environ['GITHUB_RUN_ID'], 'attempt': os.environ['GITHUB_RUN_ATTEMPT'],
'trustedContextSha': os.environ['GITHUB_SHA'], 'trustedWorkflowSha': os.environ['GITHUB_WORKFLOW_SHA'],
'trustedWorkflowRef': os.environ['GITHUB_WORKFLOW_REF'],
'package': 'com.morrowbyte.t3code', 'name': 'Crew', 'version': version, 'versionCode': code,
'apk': name, 'apkSha256': apk_sha, 'certificateSha256': expected_cert,
'abis': ['x86_64'], 'embeddedBundle': bundle, 'embeddedBundleSha256': bundle_sha,
'nativeLibraryCount': len(libraries), 'signatureVerified': True, 'zip16KB': True, 'elf16KB': True,
'jniZeroClassesDefined': True,
'dependencyReportSha256': digest(Path(os.environ['RUNNER_TEMP']) / 'morrowbyte-android-dependencies.txt'),
'deviceAcceptance': 'not-run',
}
receipt_file = output / (name + '.json')
receipt_file.write_text(json.dumps(receipt, indent=2) + '\n')
with open(os.environ['GITHUB_OUTPUT'], 'a') as outputs:
outputs.write(f'apk_sha256={apk_sha}\nreceipt_sha256={digest(receipt_file)}\nbuild_attempt={os.environ["GITHUB_RUN_ATTEMPT"]}\n')
PYAPK
- name: Upload verified Android release payload
uses: actions/upload-artifact@v4
with:
name: morrowbyte-test-android-updater-x86_64-78c21571
path: release-android/*
if-no-files-found: error
retention-days: 7
- name: Preserve resolved dependencies and generated release symbol maps
if: always()
uses: actions/upload-artifact@v4
with:
name: morrowbyte-android-updater-test-evidence-78c21571-${{ github.run_attempt }}
path: |
${{ runner.temp }}/morrowbyte-android-dependencies.txt
${{ runner.temp }}/morrowbyte-config.json
${{ runner.temp }}/morrowbyte-fingerprint.json
apps/mobile/android/app/build.gradle
apps/mobile/android/app/build/outputs/mapping/release/mapping.txt
apps/mobile/android/app/build/generated/sourcemaps/react/release/*.map
if-no-files-found: ignore
retention-days: 7
- name: Remove ephemeral signing material
if: always()
run: rm -rf -- "$RUNNER_TEMP/morrowbyte-signing"