Repository navigation
220 lines (199 loc) · 9.22 KB
/
Copy pathandroid.yml
File metadata and controls
220 lines (199 loc) · 9.22 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
name: Build Android
# Pull requests, and the pushes to `main` that publish no snapshot. A push
# that does is handled by release.yml, which builds the signed, uploadable
# artifact — running this as well would spend a second runner producing an
# unsigned one nobody installs. One that does not would otherwise be built by
# nothing at all.
on:
pull_request:
branches: ["main"]
push:
branches: ["main"]
jobs:
changes:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
android: ${{ steps.filter.outputs.android }}
native: ${{ steps.filter.outputs.native }}
release: ${{ steps.release.outputs.builds }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Nothing here pushes or fetches, so the job token is not left in
# .git/config for the steps after this one.
persist-credentials: false
# A push reads its own commit messages below: full history, without
# the file contents nothing here looks at.
fetch-depth: ${{ github.event_name == 'push' && '0' || '1' }}
filter: ${{ github.event_name == 'push' && 'blob:none' || '' }}
- uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3
id: filter
with:
filters: |
android:
- 'android/**'
- 'assets/**'
- 'lib/**'
- 'pubspec.yaml'
# The emulator job's filter, and deliberately narrower than
# `android`. What it tests — provider metadata, RemoteViews
# inflation, the Widget's own SQLite — is decided entirely by the
# native sources, the resources and the manifest. A Dart-only change
# cannot alter any of the three, so booting an emulator for one
# spends ~15 minutes of a runner to re-prove an unchanged tree.
native:
- 'android/**'
- '.github/workflows/android.yml'
- 'tool/dev/test_android_device.sh'
# Whether release.yml builds this push, for the job below. It publishes
# a snapshot only when a commit since the last tag carries a changelog
# entry; asked here of the push's own commits, which are always within
# that range. So "yes" here is always "yes" there, and a push this
# answers "no" for is built here — at worst by both, never by neither.
- name: Does release.yml build this push
id: release
if: github.event_name == 'push'
env:
BEFORE: ${{ github.event.before }}
run: |
if bash tool/release/notes.sh --any "$BEFORE..$GITHUB_SHA"; then
echo "builds=true" >> "$GITHUB_OUTPUT"
echo "this push brings a changelog entry: release.yml builds it"
else
echo "builds=false" >> "$GITHUB_OUTPUT"
echo "no changelog entry in this push: no snapshot, so it is built here"
fi
Android:
needs: changes
if: ${{ needs.changes.outputs.android == 'true' && needs.changes.outputs.release != 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
# Nothing here pushes, so the job token is not left in .git/config.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Setup Java
uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0
with:
distribution: "temurin"
java-version: "25"
cache: "gradle"
# Flutter and Dart come from mise.toml, the same pin CI and every laptop
# use. Not subosito/flutter-action with `channel: stable`: that resolves
# to whatever stable is on the day, so this job could ship an artifact
# built against an SDK nobody chose, and nothing in the build log would
# say so. See AGENTS.md → Toolchain.
- name: Install toolchain (mise)
uses: jdx/mise-action@b44d12e7d0d8ee7461bb893e1b1993500433185b # v5.2.7
- name: Cache Android NDK
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
/usr/local/lib/android/sdk/ndk/27.0.12077973
/usr/local/lib/android/sdk/ndk/28.2.13676358
key: ${{ runner.os }}-ndk-27-28
- name: Cache Android sdk
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
env:
cache-name: cache-Android-sdk
with:
path: |
/usr/local/lib/android/sdk/platforms/android-31
/usr/local/lib/android/sdk/platforms/android-33
key: ${{ runner.os }}-android-platforms-${{ env.cache-name }}-${{ hashFiles('android/gradle.properties') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
- name: Install dependencies and run build_runner
run: |
bash tool/dev/deps.sh
bash tool/dev/codegen.sh
# The Kotlin Widget tests, which `tool/dev/test.sh` cannot see: its suite
# is Dart, and none of it compiles a line of the native policy. Before
# this step existed, a change to the Widget's JSON decoding, ordering or
# presentation could ship with every other check green.
- name: Run native Widget unit tests
run: bash tool/dev/test_android.sh
# Lint reads the merged manifest and resources, which the unit tests
# cannot: a receiver without `exported`, an API-31 attribute on a minSdk-26
# app. It is a gate on new issues only — the pre-existing ones are in
# android/app/lint-baseline.xml.
- name: Run Android lint
run: bash tool/dev/lint_android.sh
# No keystore, and deliberately so. This job builds the artifact nobody
# installs — release.yml signs and uploads the one that ships — so the
# release keystore buys nothing here, and asking for it is what breaks
# the job outright: a pull request opened from a fork is handed no
# repository secrets at all, so `secrets.KEYSTORE_BASE64` is the empty
# string, android/key.properties is written with four empty values, and
# Gradle fails inside packageRelease with a keystore error that says
# nothing about forks. Every other check on such a pull request passes,
# including the iOS build, which never codesigns.
#
# android/app/build.gradle.kts already falls back to the debug signing
# config when android/key.properties is absent, so what comes out is the
# same release build, debug-signed.
- name: Build Release APK
run: bash tool/dev/build.sh android
- name: Upload Artifacts
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: DPIP-Android-Release
path: build/app/outputs/flutter-apk/*.apk
retention-days: 7
compression-level: 6
# The Widget on a real Android runtime.
#
# `tool/dev/test_android.sh` is a JVM suite: it cannot inflate a `RemoteViews`
# through the platform's own inflater, cannot read `AppWidgetProviderInfo` the
# way a launcher does, and cannot open the device's SQLite. Those three are what
# `src/androidTest` covers, and a device is the only place they can run — so
# this job exists, and a green `Android` job above says nothing about them.
#
# Gated on the `native` filter rather than the build's `android`, and
# deliberately not on the release decision: a device run is worth doing whether
# or not release.yml also builds this push.
Instrumented:
needs: changes
if: ${{ needs.changes.outputs.native == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Setup Java
uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0
with:
distribution: "temurin"
java-version: "25"
cache: "gradle"
- name: Install toolchain (mise)
uses: jdx/mise-action@b44d12e7d0d8ee7461bb893e1b1993500433185b # v5.2.7
- name: Install dependencies
run: bash tool/dev/deps.sh
# Hardware acceleration: without KVM the emulator boots in software and the
# run takes the better part of an hour.
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
| sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run the instrumented Widget tests
uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # v2
with:
# One recent platform. The JVM suite already runs the layouts and the
# store against two SDK levels (26 and 35) through Robolectric; this
# job is for the real framework, not for a version matrix it cannot
# afford.
api-level: 35
arch: x86_64
target: google_apis
disable-animations: true
script: bash tool/dev/test_android_device.sh