Repository navigation
269 lines (243 loc) · 11.2 KB
/
Copy pathdebug.yml
File metadata and controls
269 lines (243 loc) · 11.2 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
name: Build Debug
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
concurrency:
group: build-debug-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
# Pinned NDK (r28c): the Rust engine is linked with its clang.
NDK_VERSION: 28.2.13676358
jobs:
native-build:
# libdrosh.so — the Rust half that drives libghostty-vt. The APK needs it in
# jniLibs next to the engine, and it is built here rather than downloaded so
# the APK and the native library are always the same commit.
name: libdrosh.so (arm64-v8a)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-linux-android
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
workspaces: native
- name: Install libclang
run: |
set -euo pipefail
# bindgen parses the engine's headers with libclang.
#
# The apt packages for it are large — libclang-dev pulls hundreds of
# megabytes of LLVM — and the runner's Ubuntu mirror fails to resolve
# intermittently. apt then retries a mirror that is not coming, and
# the step turns into a ten-minute hang before the job times out.
#
# The PyPI wheel is one file, comes from a host that answers, and
# bindgen finds it through LIBCLANG_PATH. apt is the fallback, with
# retries, and only the library itself — not the whole toolchain.
found=""
if pip install --user --quiet libclang; then
clang_dir=$(python -c "import clang, os; print(os.path.join(os.path.dirname(clang.__file__), 'native'))")
if compgen -G "$clang_dir/libclang*.so" > /dev/null; then
echo "LIBCLANG_PATH=$clang_dir" >> "$GITHUB_ENV"
found="wheel"
fi
fi
if [ -z "$found" ]; then
sudo apt-get -o Acquire::Retries=5 update -qq
sudo apt-get -o Acquire::Retries=5 install -y -qq libclang-dev
fi
- name: Install pinned NDK
run: |
set -euo pipefail
yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --licenses > /dev/null 2>&1 || true
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" "ndk;$NDK_VERSION"
# gh prefers the API asset endpoint over the browser download URL,
# which has been answering a deterministic 504. The token is what
# authenticates the API call; the bytes are checked against SHA256SUMS
# regardless of how they travel.
- name: Fetch and verify libghostty-vt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./tools/fetch-ghostty-vt.sh
- name: Build libdrosh.so
working-directory: native
env:
DROSH_ABI: arm64-v8a
run: |
set -euo pipefail
NDK="$ANDROID_HOME/ndk/$NDK_VERSION"
TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin"
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$TOOLCHAIN/aarch64-linux-android26-clang"
export CC_aarch64_linux_android="$TOOLCHAIN/aarch64-linux-android26-clang"
export AR_aarch64_linux_android="$TOOLCHAIN/llvm-ar"
cargo build --release --target aarch64-linux-android
- name: Upload the library
uses: actions/upload-artifact@v4
with:
name: drosh-so
path: native/target/aarch64-linux-android/release/libdrosh.so
if-no-files-found: error
retention-days: 1
debug:
name: Debug APK
needs: [native-build]
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Full history, because the build derives its versionCode from the
# commit count (AndroidApplicationConventionPlugin). The default is
# fetch-depth: 1, which would make every CI build the same version —
# and an equal versionCode is exactly what lets an older APK install
# over a newer one and downgrade the database out from under Room.
fetch-depth: 0
- name: Fetch libghostty-vt
env:
GHOSTTY_VT_ABIS: arm64-v8a
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./tools/fetch-ghostty-vt.sh
- name: Fetch our own native half
uses: actions/download-artifact@v4
with:
name: drosh-so
path: android/terminal/src/main/jniLibs/arm64-v8a
- name: Stage libghostty-vt into jniLibs
run: |
set -euo pipefail
dest=android/terminal/src/main/jniLibs/arm64-v8a
mkdir -p "$dest"
cp native/ghostty/lib/arm64-v8a/libghostty-vt.so "$dest/"
# The engine must be there, and it must be the name the linker asks
# for: libdrosh.so names it in DT_NEEDED.
test -f "$dest/libghostty-vt.so"
test -f "$dest/libdrosh.so"
# The output goes to a file first. A pipe into `grep -q` is a race:
# grep exits at the first match, readelf takes a SIGPIPE, and with
# `pipefail` the pipeline reports the failure of a check that
# actually passed. The build failed on a library that linked the
# engine perfectly well.
readelf -d "$dest/libdrosh.so" > "$RUNNER_TEMP/libdrosh.dynamic"
if ! grep -q "libghostty-vt.so" "$RUNNER_TEMP/libdrosh.dynamic"; then
echo "::error::libdrosh.so does not link libghostty-vt.so"
cat "$RUNNER_TEMP/libdrosh.dynamic"
exit 1
fi
ls -l "$dest"
# chroot-ng — the guest runtime — is not in this repository. It is built
# and published by its own project, and the APK carries the published
# asset. The tag pins the release; the hash pins the bytes, because the
# build is not byte-reproducible (the debug info differs between runs), so
# rebuilding it would not give the same file. The hash is the one in the
# release's notes.
- name: Check the chroot-ng guest runtime
env:
CHROOT_NG_SHA256: 29473e3609c9e7692a3b9ab3613129dbdb46f9a1fa393c52b49fc601d2c7a01e
run: |
set -euo pipefail
# The runtime ships in the repository: it is a third-party binary that
# does not change with our code. The hash is still checked, because
# the bytes are the ones a release published and a build that
# carries different ones is a build nobody can account for.
runtime="android/linux/src/main/assets/libchrootng.so"
test -f "$runtime"
echo "${CHROOT_NG_SHA256} ${runtime}" | sha256sum -c -
ls -l "$runtime"
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
- name: Assemble debug
working-directory: android
run: ./gradlew assembleDebug --no-daemon --stacktrace --max-workers=2
# The selection model and the clipboard normalizer are pure Kotlin, so
# their tests need no device and no emulator. They are named explicitly:
# the terminal module's other unit tests use Robolectric and native
# shadows, and a failure there is not a failure of this feature.
- name: Run selection unit tests
working-directory: android
run: |
./gradlew :terminal:testDebugUnitTest \
--tests 'dev.drosh.terminal.engine.input.SelectionSnapshotTest' \
--tests 'dev.drosh.terminal.engine.input.SelectionTextTest' \
--no-daemon --stacktrace --max-workers=2
# The identity hash in the migration is a hand-copied constant, and a stale
# one is invisible here: the build passes and the app crashes on first
# launch with "Room cannot verify the data integrity". Room writes the real
# hash to android/data/schemas/ during the build, so exporting here and
# diffing turns a device crash into a red build. This step runs from the
# repository root, so the pathspecs carry the `android/` prefix.
- name: Check Room schema matches the committed snapshot
run: |
if ! git diff --quiet -- android/data/schemas || [ -n "$(git ls-files --others --exclude-standard -- android/data/schemas)" ]; then
echo "::error::The Room schema in android/data/schemas does not match the committed"
echo "::error::snapshot. If you changed a @Entity, also update"
echo "::error::DroshDatabase.IDENTITY_HASH — a stale hash builds clean and"
echo "::error::crashes on first launch with 'Room cannot verify data"
echo "::error::integrity'."
git status --porcelain -- android/data/schemas
find android/data/schemas -name "*.json" -exec cat {} \;
exit 1
fi
- name: Upload Room schema on mismatch
if: failure()
uses: actions/upload-artifact@v4
with:
name: room-schema-mismatch
path: android/data/schemas
if-no-files-found: warn
retention-days: 1
# The guest runtime travels inside the APK, and a missing one is an
# ENOENT at the first session with nothing in the UI to say why. Fail
# here instead of on the device.
- name: Check the APK carries the guest runtime
run: |
set -euo pipefail
APK=$(ls android/app/build/outputs/apk/debug/*.apk | head -1)
unzip -l "$APK" | grep -q "assets/libchrootng.so"
echo "$APK contains libchrootng.so"
# Pull requests (especially from forks) cannot use the private-repo
# secret, so their APK stays a short-lived Actions artifact. Branch and
# dispatch builds go to the private repo instead: a public repo's
# artifacts are downloadable by anyone with read access.
- name: Upload debug APK (pull requests)
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: drosh-debug-arm64-v8a-apk
path: android/app/build/outputs/apk/debug/app-arm64-v8a-debug.apk
if-no-files-found: warn
retention-days: 1
- name: Publish debug APK to the private build repo
if: github.event_name != 'pull_request'
env:
GH_TOKEN: ${{ secrets.PRIVATE_RELEASE_TOKEN }}
PRIVATE_REPO: mmuhofy/Drosh-builds
run: |
set -euo pipefail
APK="android/app/build/outputs/apk/debug/app-arm64-v8a-debug.apk"
SUM="android/app/build/outputs/apk/debug/drosh-debug-arm64-v8a-debug.apk.sha256"
test -f "$APK"
sha256sum "$APK" > "$SUM"
TAG="debug-${GITHUB_SHA::7}"
NOTES="Debug build of ${GITHUB_SHA} (${GITHUB_REF_NAME})"
if gh release view "$TAG" --repo "$PRIVATE_REPO" >/dev/null 2>&1; then
gh release upload "$TAG" "$APK" "$SUM" --repo "$PRIVATE_REPO" --clobber
else
gh release create "$TAG" "$APK" "$SUM" \
--repo "$PRIVATE_REPO" --title "$TAG" --notes "$NOTES"
fi