Repository navigation
201 lines (179 loc) · 7.85 KB
/
Copy pathandroid-runtime-gate.yml
File metadata and controls
201 lines (179 loc) · 7.85 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
# SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited
#
# SPDX-License-Identifier: MIT OR Apache-2.0
name: Android Runtime Gate
on:
workflow_call:
outputs:
verified_sha:
value: ${{ jobs.runtime.outputs.verified_sha }}
permissions:
contents: read
jobs:
runtime:
name: Minified Android consumer
runs-on: ubuntu-24.04
timeout-minutes: 35
outputs:
verified_sha: ${{ steps.runtime.outputs.sha }}
steps:
- name: Checkout candidate
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
persist-credentials: false
- name: Checkout release-readiness
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
repository: reallyme/release-readiness
ref: 16aab5287de498e858ff3b85d9e66d7c9f7ebb74
path: .release-readiness
persist-credentials: false
- name: Set up Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "26"
- name: Authenticate release-readiness package
run: node scripts/run_pinned_release_readiness.mjs --check-pins
- name: Install Java
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
problem-matcher: true
distribution: temurin
java-version: '21'
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master
with:
toolchain: 1.100.0
- name: Install Android NDK
run: |
{ yes 2>/dev/null || true; } | "${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" "platforms;android-37.0" "ndk;29.0.14206865"
echo "ANDROID_NDK_HOME=${ANDROID_HOME}/ndk/29.0.14206865" >>"$GITHUB_ENV"
# Save on main so later candidates can reuse the cache and PR code
# cannot seed it. Queue-only repositories can refresh it by dispatching
# CI on main when the cache key changes or the entry is evicted.
- name: Restore Gradle cache
id: android-cache
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: android-runtime-${{ runner.os }}-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', '**/gradle-wrapper.properties', '**/libs.versions.toml', 'scripts/prepare-android-runtime.sh') }}
- name: Enable emulator acceleration
shell: bash
run: |
test -c /dev/kvm
sudo chown "$(id -u):$(id -g)" /dev/kvm
test -r /dev/kvm
test -w /dev/kvm
- name: Stage Android Maven publication
shell: bash
env:
MAVEN_REPOSITORY: ${{ runner.temp }}/android-publication/repository
run: |
# Package once. The consumer resolves this publication by its Maven
# coordinates so the test covers the same AAR that preflight uses.
mkdir -p "$MAVEN_REPOSITORY"
bash -e -o pipefail scripts/stage-android-publication.sh "$MAVEN_REPOSITORY"
node .release-readiness/scripts/android-runtime.mjs seal-publication "$MAVEN_REPOSITORY" "$GITHUB_SHA"
- name: Prepare Android consumer and emulator
shell: bash
env:
ANDROID_AVD_HOME: ${{ runner.temp }}/android-avd
ANDROID_AVD_NAME: reallyme-runtime
APK_PATH: ${{ runner.temp }}/android-runtime.apk
MAVEN_REPOSITORY: ${{ runner.temp }}/android-publication/repository
run: |
bash -e -o pipefail scripts/prepare-android-runtime.sh "$APK_PATH" "$ANDROID_AVD_NAME" "$MAVEN_REPOSITORY"
test -s "$APK_PATH"
- name: Verify minified Android consumer
id: runtime
shell: bash
env:
ANDROID_AVD_HOME: ${{ runner.temp }}/android-avd
ANDROID_AVD_NAME: reallyme-runtime
ANDROID_SERIAL: emulator-5554
APK_PATH: ${{ runner.temp }}/android-runtime.apk
MAVEN_REPOSITORY: ${{ runner.temp }}/android-publication/repository
run: |
sha=$(git rev-parse --verify HEAD)
test "$sha" = "$GITHUB_SHA"
export ADB="${ANDROID_HOME:?}/platform-tools/adb"
helper=.release-readiness/scripts/android-runtime.mjs
emulator_log="$RUNNER_TEMP/android-runtime-emulator.log"
emulator_pid=
stop_emulator() {
if [[ -z "$emulator_pid" ]]; then
return
fi
kill -TERM "$emulator_pid" 2>/dev/null || true
for ((poll = 0; poll < 5; poll += 1)); do
kill -0 "$emulator_pid" 2>/dev/null || break
sleep 1
done
kill -KILL "$emulator_pid" 2>/dev/null || true
wait "$emulator_pid" 2>/dev/null || true
emulator_pid=
}
collect_diagnostics() {
node "$helper" diagnostics "$ANDROID_SERIAL" || true
# Prefix host output and neutralize legacy workflow command markers.
LC_ALL=C tail -n 200 "$emulator_log" | tr -cd '\11\12\40-\176' | sed 's/##\[/# #[/g; s/^/emulator | /' >&2 || true
}
cleanup() {
local result=$?
trap - EXIT
if [[ -n "$emulator_pid" ]]; then
if (( result != 0 )); then
collect_diagnostics
fi
stop_emulator
fi
exit "$result"
}
trap cleanup EXIT
timeout --kill-after=2s 10s "$ADB" start-server
for attempt in 1 2; do
# Select a supported software backend for the installed emulator;
# the deprecated indirect backend crashes current system images.
"$ANDROID_HOME/emulator/emulator" -avd "$ANDROID_AVD_NAME" -port 5554 \
-no-window -no-audio -no-boot-anim -no-snapshot -wipe-data -partition-size 4096 -gpu software \
>"$emulator_log" 2>&1 &
emulator_pid=$!
if bash -e -o pipefail scripts/install-android-runtime-apk.sh "$ANDROID_SERIAL" "$APK_PATH"; then
# Preserve system, events and crash buffers for failure diagnostics.
timeout --kill-after=2s 10s "$ADB" -s "$ANDROID_SERIAL" logcat -b main -c
bash -e -o pipefail scripts/test-android-runtime.sh "$ANDROID_SERIAL"
node "$helper" verify-publication "$MAVEN_REPOSITORY" "$sha"
printf 'sha=%s\n' "$sha" >>"$GITHUB_OUTPUT"
break
else
result=$?
if (( result != 75 || attempt == 2 )); then
exit "$result"
fi
echo "Restarting the Android emulator after a device readiness or package-service failure." >&2
collect_diagnostics
stop_emulator
fi
done
# Release qualification accepts a main run or, with a merge queue, the
# queue run that main fast-forwarded to. PR runs never qualify.
- name: Upload tested Android publication
if: >-
(github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')) ||
(github.event_name == 'merge_group' && startsWith(github.ref, 'refs/heads/gh-readonly-queue/main/'))
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
with:
name: android-maven-${{ github.sha }}
path: ${{ runner.temp }}/android-publication/
if-no-files-found: error
overwrite: true
- name: Save Gradle cache
if: github.ref == 'refs/heads/main' && steps.android-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ steps.android-cache.outputs.cache-primary-key }}