Repository navigation
393 lines (381 loc) · 21.7 KB
/
Copy pathphone.yml
File metadata and controls
393 lines (381 loc) · 21.7 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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# Copyright 2026 Han Li and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# The phone app (mygo/phone), which mygo builds for Android. The build job makes the APK and the
# AAB for the x86_64 emulator, with the debug key (the release is release.yml's job). The emulator
# job starts the end-to-end build of the desktop application, pairs the emulator with it through
# the address 10.0.2.2 (the one at which the emulator reaches this runner), and drives the paired
# session the way a person does: the pairing link comes in through the deep link, the tabs are
# visited with screenshots, and the app's log is checked for errors. It measures the memory of the
# app cold (the median of five starts) and paired, for memory.yml (vfxtool measure-apk), and it presses
# the key back with the dialog of the pairing open, which must close the dialog and leave the app in
# front (--check-back-key: nothing but an emulator sees an app leave), and reads what the field of the
# pairing link asks of the keyboard, which must be the keyboard of addresses with no capitalization and
# no corrections (--check-input-type: nothing but an emulator sees what a keyboard is told). The desktop
# application it pairs with runs against the fake vfox (a machine that has Node.js, Java and Flutter
# installed, and plugins to offer), so the tabs show what a person has, and the same run takes the
# pictures of the user guide (the phone-pictures artifact: raw/ as they came, framed/ without the
# status bar of the emulator; docs/en/dev/contributing.md#screenshots). The signing job rehearses what
# release.yml does to the APK after the approval, on a Windows runner as the release does and with
# the same script (shared/scripts/sign-apk.ps1), with a key that is made for the run and is no one's:
# the release is started by hand from main, the release key is in an environment that only main and
# the tags can use, so no other run can try the signing with the real one. The versions are in
# mygo/phone/versions.env, and the version of mygo in mygo/go.mod must be the same one.
name: phone
on:
push:
branches: [main]
paths:
- mygo/phone/**
- mygo/pair/**
- mygo/ui/kit/**
- mygo/VERSION
- mygo/go.mod
- mygo/go.sum
- mygo/versions.env
- shared/tooling/**
- shared/icons.json
- shared/scripts/sign-apk.ps1
- .github/workflows/phone.yml
pull_request:
paths:
- mygo/phone/**
- mygo/pair/**
- mygo/ui/kit/**
- mygo/VERSION
- mygo/go.mod
- mygo/go.sum
- mygo/versions.env
- shared/tooling/**
- shared/icons.json
- shared/scripts/sign-apk.ps1
- .github/workflows/phone.yml
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# The packages of the desktop application for its end-to-end build (the ones of mygo.yml that
# the virtual display and the fonts need).
LINUX_PACKAGES: >-
build-essential libgtk-3-0t64 fontconfig fonts-ubuntu fonts-noto-cjk
xvfb xauth dbus-x11
jobs:
build:
name: Build the APK and the AAB for the emulator
# Forks do not run CI.
if: github.repository == 'version-fox/vfox-plus'
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Read the pinned versions
run: |
grep -hE '^[A-Z0-9_]+=' mygo/phone/versions.env >> "$GITHUB_ENV"
grep -hE '^GO_VERSION=' mygo/versions.env >> "$GITHUB_ENV"
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: mygo/go.sum
- name: Set up JDK
# Gradle, which mygo runs for the Android project, does not run on newer JDKs.
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
- name: Set up the Android SDK
uses: android-actions/setup-android@be39fa834029ff78f1a44aa3bb0819b8fc2bd8fd # v4.0.4
with:
# The default package list still names the `tools` package, which
# Google removed; install only what the build needs.
packages: platform-tools platforms;android-${{ env.ANDROID_SDK_PLATFORM }} build-tools;${{ env.ANDROID_SDK_BUILD_TOOLS }} build-tools;${{ env.ANDROID_GRADLE_BUILD_TOOLS }} ndk;${{ env.ANDROID_NDK_VERSION }}
- name: Install the mygo CLI
run: |
go install "github.com/egoist/mygo/cmd/mygo@v$MYGO_VERSION"
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- name: Build vfxtool
run: go -C shared/tooling build -o "$RUNNER_TEMP/vfxtool" ./cmd/vfxtool
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
# Where vfxtool prepare keeps the npm package that the icons come from.
path: ~/.cache/vfox-plus/icons
key: icons-${{ hashFiles('shared/icons.json') }}
- name: Prepare the embedded assets
# The translations, the icons and the licenses that mygo compiles into the application
# (mygo/assets, which the repository does not hold), as mygo.yml prepares them. The build
# of the phone app compiles the module, so it needs them.
run: '"$RUNNER_TEMP/vfxtool" prepare --root mygo'
- name: Write the icons of the app
# The repository holds no binary files: the icons that mygo.json names are drawn by vfxtool.
run: '"$RUNNER_TEMP/vfxtool" appicon mygo/phone/resources'
- name: Build the APK and the AAB
# mygo builds the Go code for x86_64 and the Android project with Gradle, and signs them
# with the debug key, as the configuration has no keystore. Its files are in mygo/phone/dist/android.
run: mygo build -platform android/amd64
working-directory: mygo/phone
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: vfox-plus-android-amd64
path: mygo/phone/dist/android/*
if-no-files-found: error
emulator:
name: Pair, drive and measure the app on an emulator
# Forks do not run CI.
if: github.repository == 'version-fox/vfox-plus'
needs: build
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Read the pinned versions
run: |
grep -hE '^[A-Z0-9_]+=' mygo/phone/versions.env >> "$GITHUB_ENV"
grep -hE '^GO_VERSION=' mygo/versions.env >> "$GITHUB_ENV"
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: mygo/go.sum
- name: Install the Linux packages
uses: ./.github/actions/install-linux-packages
with:
packages: ${{ env.LINUX_PACKAGES }}
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
# Where vfxtool prepare keeps the npm package that the icons come from.
path: ~/.cache/vfox-plus/icons
key: icons-${{ hashFiles('shared/icons.json') }}
- name: Build vfxtool
run: go -C shared/tooling build -o "$RUNNER_TEMP/vfxtool" ./cmd/vfxtool
- name: Prepare the embedded assets of the desktop application
run: '"$RUNNER_TEMP/vfxtool" prepare --root mygo'
- name: Build the end-to-end desktop application
run: '"$RUNNER_TEMP/vfxtool" build --e2e --root mygo "$RUNNER_TEMP/vfox-plus-e2e"'
- name: Start the desktop application in a virtual display
# The end-to-end build writes its loopback link to the file when it starts, and lists
# 10.0.2.2 as an address of this computer (VFOX_PLUS_E2E_ADDRESSES), so that the link of
# the phone names the address at which the emulator reaches this runner. It runs against the
# fake vfox, as the pictures of the documentation are taken (docs/en/dev/contributing.md): a
# copy of vfxtool named vfox is first on the PATH, and acts as vfox with the fixtures, as a
# machine that has Node.js, Java and Flutter installed (VFOX_PLUS_FAKE_INVENTORY=profiles).
# Its home is a directory of its own. It runs until the last step of the job stops it.
run: |
set -eu
home="$RUNNER_TEMP/phone-e2e/home"
mkdir -p "$home/bin" "$home/run" "$home/.config/vfox-plus"
chmod 700 "$home/run"
cp "$RUNNER_TEMP/vfxtool" "$home/bin/vfox"
HOME="$home" XDG_CONFIG_HOME="$home/.config" XDG_RUNTIME_DIR="$home/run" PATH="$home/bin:$PATH" NO_COLOR=1 \
VFOX_PLUS_FIXTURES="$PWD/shared/fixtures/vfox-1.1.0" VFOX_PLUS_FAKE_INVENTORY=profiles \
VFOX_PLUS_E2E_ADDRESSES=10.0.2.2 VFOX_PLUS_E2E_LINK="$RUNNER_TEMP/phone-e2e/loopback-link.txt" \
setsid xvfb-run -a -s "-screen 0 1280x800x24" dbus-run-session -- "$RUNNER_TEMP/vfox-plus-e2e" \
> "$RUNNER_TEMP/phone-e2e/desktop.log" 2>&1 < /dev/null &
- name: Download the APK
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: vfox-plus-android-amd64
path: ${{ runner.temp }}/apk
- name: Find the APK
run: |
set -eu
apk="$(find "$RUNNER_TEMP/apk" -name '*.apk')"
if [ "$(printf '%s\n' "$apk" | grep -c .)" != 1 ]; then
echo "::error::want one APK in the artifact, found: $apk"
exit 1
fi
echo "APK=$apk" >> "$GITHUB_ENV"
- name: Set up the Android SDK
# The emulator runner installs the emulator and the system image too, when they are missing.
uses: android-actions/setup-android@be39fa834029ff78f1a44aa3bb0819b8fc2bd8fd # v4.0.4
with:
packages: platform-tools build-tools;${{ env.ANDROID_SDK_BUILD_TOOLS }} emulator system-images;android-${{ env.ANDROID_EMULATOR_API }};${{ env.ANDROID_SYSTEM_IMAGE_TARGET }};x86_64
- 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
- uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # v2.38.0
with:
api-level: ${{ env.ANDROID_EMULATOR_API }}
target: ${{ env.ANDROID_SYSTEM_IMAGE_TARGET }}
arch: x86_64
profile: pixel_6
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
# One line: the runner executes the script line by line, each in its own shell. The link is
# asked for at the last moment, because a pairing link lasts five minutes, and the emulator
# takes minutes to boot. The memory of the first screen goes to memory-android (the one line
# memory.txt the report reads: the median of five cold starts, because one start of an
# emulator reads anything from 29 to 49 MB of PSS, and the five readings and the whole report
# of each are beside it), the paired one to memory-paired.txt beside memory.txt (the evidence
# step copies it into phone-e2e-android), the screenshots of the tabs to shots, and the pictures
# of the user guide to phone-pictures/raw. The link goes to a file of its own: a secret, never printed.
script: ${{ runner.temp }}/vfxtool phone-link --loopback-link-file ${{ runner.temp }}/phone-e2e/loopback-link.txt --host 10.0.2.2 --output ${{ runner.temp }}/phone-e2e/pairing-link.txt --wait 180 && ${{ runner.temp }}/vfxtool measure-apk --apk ${{ env.APK }} --output ${{ runner.temp }}/memory-android --cold-runs 5 --screenshot ${{ runner.temp }}/screenshot-android.png --pair-link-file ${{ runner.temp }}/phone-e2e/pairing-link.txt --shots ${{ runner.temp }}/phone-e2e/shots --check-back-key --check-input-type --pictures ${{ runner.temp }}/phone-pictures/raw
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: memory-android
path: ${{ runner.temp }}/memory-android/memory.txt
if-no-files-found: error
overwrite: true
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: screenshot-android
path: ${{ runner.temp }}/screenshot-android.png
if-no-files-found: error
overwrite: true
- name: Look at the server of the desktop application
# What the emulator reaches at 10.0.2.2 is the loopback interface of this computer, at the port
# of the pairing link. The step says whether the application listens at that port and completes
# a TLS handshake there, and it prints the port only: the link is a secret, so a link without a
# port is not printed either.
if: always()
run: |
mkdir -p "$RUNNER_TEMP/phone-e2e"
{
link="$RUNNER_TEMP/phone-e2e/pairing-link.txt"
if [ -s "$link" ]; then
port="$(sed -E 's#^https://[^:/]+:([0-9]+)/.*#\1#' "$link")"
case "$port" in
''|*[!0-9]*) echo "the pairing link names no port" ;;
*)
echo "the pairing link names port $port"
ss -ltn | grep ":$port " || echo "nothing listens at port $port"
openssl s_client -connect "127.0.0.1:$port" -brief </dev/null 2>&1 | head -n 12 || true
;;
esac
else
echo "no pairing link was made"
fi
} 2>&1 | tee "$RUNNER_TEMP/phone-e2e/desktop-listening.txt"
- name: Keep the evidence of the paired session
if: always()
run: |
mkdir -p "$RUNNER_TEMP/evidence"
cp -r "$RUNNER_TEMP/phone-e2e/shots" "$RUNNER_TEMP/evidence/" 2>/dev/null || true
cp "$RUNNER_TEMP/phone-e2e/desktop.log" "$RUNNER_TEMP/phone-e2e/desktop-listening.txt" "$RUNNER_TEMP/evidence/" 2>/dev/null || true
cp "$RUNNER_TEMP/memory-android/memory-paired.txt" "$RUNNER_TEMP/evidence/" 2>/dev/null || true
# The five readings of the cold starts and the whole report of `dumpsys meminfo` of each, which say
# what moved when two runs differ (the category of memory), where the line says only that it did.
cp -r "$RUNNER_TEMP/memory-android" "$RUNNER_TEMP/evidence/" 2>/dev/null || true
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
# The screens of the tabs, their dumps of the accessibility tree, the log of the app, the
# log of the desktop application, and the readings of the memory. The pairing link is not among them.
name: phone-e2e-android
path: ${{ runner.temp }}/evidence/*
if-no-files-found: warn
overwrite: true
- name: Frame the pictures of the user guide
# vfxtool frame-phone cuts the status bar off each picture (--top 118: its height on this emulator, a
# Pixel 6 of 1080 by 2400, which shows the real time, and what the system draws there is not the same from
# one run to the next) and gives it the corners of a phone display and a border (the pictures of the
# guide are framed: the cream screens have no edge against the white page of GitHub). The raw ones are
# kept as well.
if: always()
run: |
set -eu
raw="$RUNNER_TEMP/phone-pictures/raw"
[ -d "$raw" ] || exit 0
mkdir -p "$RUNNER_TEMP/phone-pictures/framed"
for picture in "$raw"/*.png; do
name="$(basename "$picture")"
top=118
if [ "$name" = android-add-plugin.png ]; then
# The shade of the dialog does not cover the bar that Android keeps over the page of a tab: it is 168 px
# high (the status bar and the 64 dp of the toolbar, which has no title there, as the tabs draw their
# own), and under the shade it would be a bright band. The picture is cut under it.
top=168
fi
"$RUNNER_TEMP/vfxtool" frame-phone --top "$top" "$picture" "$RUNNER_TEMP/phone-pictures/framed/$name"
done
ls -l "$RUNNER_TEMP/phone-pictures/framed"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
# The pictures of the user guide of the phone app, as the app draws them on the emulator, in
# English: framed/ is what the guide links once it is on the image host, raw/ the screens as
# they came.
name: phone-pictures
path: ${{ runner.temp }}/phone-pictures/*
if-no-files-found: warn
overwrite: true
- name: Stop the desktop application
if: always()
# The bracket keeps pkill from matching the shell that runs this line.
run: pkill -f '[v]fox-plus-e2e' || true
signing:
name: Rehearse the signing of the APK of the release
# Forks do not run CI.
if: github.repository == 'version-fox/vfox-plus'
needs: build
# The runner of the job of release.yml that signs the APK. Nothing here is a secret: the key is
# made by the job, and nothing else of the job is the release's but the steps.
runs-on: windows-2025-vs2026
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Read the pinned versions
shell: pwsh
run: |
Get-Content mygo/phone/versions.env | ForEach-Object { $_.Trim() } | Where-Object { $_ -match '^[A-Z0-9_]+=' } | Add-Content -Path $env:GITHUB_ENV
- name: Set up JDK
# apksigner and keytool run on Java, at the version that the phone app is built with.
uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: ${{ env.JAVA_VERSION }}
- name: Set up the Android build tools
# zipalign and apksigner come with the build tools of the pinned version, as in release.yml.
uses: android-actions/setup-android@be39fa834029ff78f1a44aa3bb0819b8fc2bd8fd # v4.0.4
with:
packages: "build-tools;${{ env.ANDROID_SDK_BUILD_TOOLS }}"
- name: Download the APK
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: vfox-plus-android-amd64
path: apk
- name: Sign the APK as the release does, with a key that is no one's
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
if (-not $env:ANDROID_HOME) { throw "ANDROID_HOME is not set: the Android SDK setup did not run" }
$buildTools = Join-Path $env:ANDROID_HOME "build-tools/$env:ANDROID_SDK_BUILD_TOOLS"
$apksigner = Join-Path $buildTools "apksigner.bat"
$apks = @(Get-ChildItem -Path apk -Filter *.apk)
if ($apks.Count -ne 1) { throw "want one APK in the artifact, found: $($apks.Name -join ', ')" }
$unsigned = $apks[0].FullName
# What the release signs is an APK that mygo signed with the debug key. If it is not one, the
# check of the script that no debug key is left means nothing.
$before = & $apksigner verify --print-certs $unsigned | Out-String
if ($LASTEXITCODE -ne 0) { throw "apksigner verify failed with exit code $LASTEXITCODE" }
if ($before -notmatch "CN=Android Debug") { throw "the APK of the build is not signed with the debug key of mygo:`n$before" }
# The key is made here, for this run, and is no one's: a password that nothing else knows.
$keystore = Join-Path $env:RUNNER_TEMP "rehearsal.p12"
$password = [guid]::NewGuid().ToString("N")
Write-Host "::add-mask::$password"
& keytool -genkeypair -keystore $keystore -storetype PKCS12 -alias rehearsal -keyalg RSA -keysize 2048 -validity 1 -dname "CN=vfox-plus signing rehearsal" -storepass $password -keypass $password
if ($LASTEXITCODE -ne 0) { throw "keytool failed with exit code $LASTEXITCODE" }
$env:ANDROID_RELEASE_KEY_ALIAS = "rehearsal"
$env:ANDROID_RELEASE_STORE_PASSWORD = $password
$env:ANDROID_RELEASE_KEY_PASSWORD = $password
$signed = Join-Path $env:RUNNER_TEMP "signed/vfox-plus-rehearsal.apk"
& (Join-Path $env:GITHUB_WORKSPACE "shared/scripts/sign-apk.ps1") -Unsigned $unsigned -Signed $signed -Keystore $keystore -BuildTools $buildTools
# The script checks that no debug key is left; here it is the key of the rehearsal, and only it.
$after = & $apksigner verify --print-certs $signed | Out-String
if ($LASTEXITCODE -ne 0) { throw "apksigner verify failed with exit code $LASTEXITCODE" }
if ($after -notmatch "CN=vfox-plus signing rehearsal") { throw "the APK is not signed with the key of the rehearsal:`n$after" }
if ($after -match "CN=Android Debug") { throw "the APK still has the debug certificate:`n$after" }
Write-Host $after
Remove-Item -Force -ErrorAction SilentlyContinue -LiteralPath $keystore