Repository navigation
283 lines (263 loc) · 10.8 KB
/
Copy pathandroid-debug.yml
File metadata and controls
283 lines (263 loc) · 10.8 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
name: Android debug
# An installable APK for every push, so a build break in the Android layer is
# caught in minutes rather than at release time. This workflow builds the
# debug flavour with the debug key on purpose — it is a smoke build, not a
# release. The signed, publishable artifact comes from android-release.yml.
#
# Analysis and tests are their own workflows (analyze.yml, test.yml) so a
# failure names the stage that failed; this one records its toolchain and
# Gradle output as a commit comment when a build fails, because the raw
# Actions log needs repository sign-in to read.
on:
push:
branches: ["arena/**", "main"]
pull_request:
branches: ["main"]
workflow_dispatch:
concurrency:
group: android-debug-${{ github.ref }}
cancel-in-progress: true
env:
FLUTTER_VERSION: "3.47.5"
jobs:
debug:
name: Build debug APK
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: write
steps:
- uses: actions/checkout@v5
- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "17"
- uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: stable
cache: true
- run: flutter pub get
- run: dart run build_runner build --delete-conflicting-outputs
- name: Build debug APK
id: apk
continue-on-error: true
run: |
set +e
rm -f /tmp/android_codes.env
flutter build apk --debug > /tmp/apk_debug.txt 2>&1
code=$?
echo "debug_code=$code" >> /tmp/android_codes.env
tail -c 40000 /tmp/apk_debug.txt
# The real code, not 0: with `continue-on-error` this keeps the job
# alive while still marking the step failed, which is what the
# diagnostics step below keys off. Ending with `exit 0` makes a
# failed build report success and produce no report at all.
exit $code
# Inspect what was actually built, on every push: identity, version,
# target SDK, permissions, exported components, native ABIs and any
# accidental key material. The debug key is expected here, so the script
# is told not to fail on it — the release workflow checks that part for
# real, with the release artifact.
- name: Inspect the APK
id: inspect
if: steps.apk.outcome == 'success'
continue-on-error: true
run: |
set +e
APK=$(ls build/app/outputs/flutter-apk/*.apk | head -1)
bash tools/verify_release_artifact.sh --allow-debug-signature "$APK" > /tmp/inspect.txt 2>&1
echo "inspect_code=$?" >> /tmp/android_codes.env
cat /tmp/inspect.txt
exit 0 # a failing inspection is reported, not fatal to this step
# The release variant is the one that runs R8 and shrinks resources, so
# it is the one where a missing keep rule shows up as a build failure.
# Without signing secrets it is signed with the debug key and says so in
# the Gradle log; the artifact is still proof that the release build
# compiles, that the AAB is produced, and that the R8 mapping exists.
- name: Build the release AAB (signed with the debug key until secrets exist)
id: aab
continue-on-error: true
run: |
set +e
flutter build appbundle --release > /tmp/aab.txt 2>&1
code=$?
echo "aab_code=$code" >> /tmp/android_codes.env
tail -c 20000 /tmp/aab.txt
exit $code
- name: Build the release APK (signed with the debug key until secrets exist)
id: relapk
continue-on-error: true
run: |
set +e
flutter build apk --release > /tmp/relapk.txt 2>&1
code=$?
echo "relapk_code=$code" >> /tmp/android_codes.env
tail -c 20000 /tmp/relapk.txt
exit $code
- name: Name and keep the unsigned smoke artifacts
id: smoke
if: always() && steps.relapk.outcome == 'success'
run: |
set -e
mkdir -p dist-smoke
# Named so nobody can mistake one of these for a publishable build:
# they are signed with the debug key, and the release workflow is the
# only thing that produces artifacts with the upload key.
cp build/app/outputs/flutter-apk/app-release.apk \
dist-smoke/wonder-cv-builder-release-UNSIGNED-smoke.apk
cp build/app/outputs/bundle/release/app-release.aab \
dist-smoke/wonder-cv-builder-release-UNSIGNED-smoke.aab
ls -lh dist-smoke
- name: Upload the smoke artifacts
if: always() && steps.smoke.outcome == 'success'
uses: actions/upload-artifact@v5
with:
name: smoke-unsigned-${{ github.sha }}
path: dist-smoke/*
retention-days: 14
- name: Inspect the release AAB
id: inspect_aab
if: always() && steps.aab.outcome == 'success'
continue-on-error: true
run: |
set +e
AAB=$(ls build/app/outputs/bundle/release/*.aab | head -1)
bash tools/verify_release_artifact.sh --allow-debug-signature /dev/null "$AAB" > /tmp/inspect_aab.txt 2>&1
echo "inspect_aab_code=$?" >> /tmp/android_codes.env
cat /tmp/inspect_aab.txt
exit 0
- name: Publish the AAB inspection table
if: always() && github.event_name == 'push' && steps.inspect_aab.outcome == 'success'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
{
echo "## Release AAB inspection for ${GITHUB_SHA:0:7}"
echo
echo '```'
cat /tmp/inspect_aab.txt
echo '```'
} > /tmp/aab_report.md
payload=$(python3 -c 'import json; print(json.dumps({"body": open("/tmp/aab_report.md").read()}))')
curl -sS -X POST \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/comments" \
-d "$payload" > /dev/null
- name: Publish the inspection table
if: always() && github.event_name == 'push' && steps.inspect.outcome != 'skipped'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
{
echo "## APK inspection for ${GITHUB_SHA:0:7}"
echo
echo '```'
cat /tmp/inspect.txt
echo '```'
} > /tmp/inspect_report.md
payload=$(python3 -c 'import json; print(json.dumps({"body": open("/tmp/inspect_report.md").read()}))')
curl -sS -X POST \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/comments" \
-d "$payload" > /dev/null
- name: Publish Android diagnostics as a commit comment
if: always()
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
debug_code=0
if [ -f /tmp/android_codes.env ]; then
# shellcheck disable=SC1091
. /tmp/android_codes.env
fi
if [ "${debug_code:-0}" = "0" ] && [ "${aab_code:-0}" = "0" ]; then
echo "The debug build and the release bundle both succeeded; nothing to publish."
exit 0
fi
{
echo "## Android debug build diagnostics for ${GITHUB_SHA:0:7}"
echo
echo "* flutter build apk --debug exit: ${debug_code}"
echo "* flutter build appbundle --release exit: ${aab_code:-not run}"
echo "* flutter build apk --release exit: ${relapk_code:-not run}"
echo
echo "<details><summary>toolchain</summary>"
echo
echo '```'
flutter --version || true
java -version 2>&1 || true
cat android/app/build.gradle.kts 2>/dev/null || true
echo '```'
echo "</details>"
echo
echo "<details open><summary>gradle output</summary>"
echo
echo '```'
tail -c 50000 /tmp/apk_debug.txt || true
echo '```'
echo "</details>"
if [ -f /tmp/aab.txt ]; then
echo
echo "<details open><summary>flutter build appbundle --release</summary>"
echo
echo '```'
tail -c 50000 /tmp/aab.txt || true
echo '```'
echo "</details>"
fi
} > /tmp/android_report.md
payload=$(python3 -c 'import json; print(json.dumps({"body": open("/tmp/android_report.md").read()}))')
curl -sS -X POST \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GITHUB_SHA}/comments" \
-d "$payload" > /dev/null
- name: Upload debug APK
if: always()
uses: actions/upload-artifact@v5
with:
name: wonder-cv-builder-debug-${{ github.sha }}
path: build/app/outputs/flutter-apk/*.apk
if-no-files-found: warn
- name: Fail if the build or the inspection failed
if: always()
run: |
if [ ! -f /tmp/android_codes.env ]; then
echo "No result file was written; treating this as a failure."
exit 1
fi
# shellcheck disable=SC1091
. /tmp/android_codes.env
echo "debug build exit: ${debug_code:-unset}"
echo "apk inspection exit: ${inspect_code:-not run}"
echo "release AAB exit: ${aab_code:-not run}"
if [ "${debug_code:-1}" != "0" ]; then
exit 1
fi
# The release variant must build: it is the one that runs R8, and a
# keep-rule mistake that only appears there must not reach a tag.
if [ "${aab_code:-1}" != "0" ]; then
echo "::error::the release app bundle did not build"
exit 1
fi
# ... and so must the release APK, which is what Bazaar and Myket
# take. It is a different Gradle task with its own packaging step.
if [ "${relapk_code:-1}" != "0" ]; then
echo "::error::the release APK did not build"
exit 1
fi
# A smoke build that produces an APK with the wrong package, an
# unexpected permission or an exported component nobody meant to
# export is a failure even though Gradle succeeded.
if [ "${inspect_code:-1}" != "0" ]; then
exit 1
fi