Files
AFFiNE/.github/workflows/np-mobile.yml
T

811 lines
34 KiB
YAML

name: Native Playground Mobile CI
on:
push:
branches:
- 'darksky/np/mobile'
- 'darksky/np/mobile-**'
workflow_dispatch:
inputs:
force_all:
description: Force all native mobile jobs
required: false
type: boolean
default: false
concurrency:
group: np-mobile-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_ENCODED_RUSTFLAGS: ''
CARGO_INCREMENTAL: '0'
CARGO_NET_GIT_FETCH_WITH_CLI: 'true'
CARGO_PROFILE_DEV_DEBUG: '0'
CARGO_PROFILE_TEST_DEBUG: '0'
CARGO_TERM_COLOR: always
jobs:
changes:
name: Changed Paths
runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
web-host-only: ${{ steps.classify.outputs.web_host_only }}
desktop-leaf-only: ${{ steps.classify.outputs.desktop_leaf_only }}
desktop-rs-only: ${{ steps.classify.outputs.desktop_rs_only }}
backend-only: ${{ steps.classify.outputs.backend_only }}
web-wrapper-only: ${{ steps.classify.outputs.web_wrapper_only }}
apple-specific: ${{ steps.base.outputs.force_all == 'true' && 'true' || steps.classify.outputs.apple_specific }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 50
- name: Resolve the base commit
id: base
env:
BEFORE: ${{ github.event.before }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
INPUT_FORCE_ALL: ${{ inputs.force_all }}
run: |
set -euo pipefail
force_all=false
sha=""
if [ "${INPUT_FORCE_ALL:-false}" = "true" ]; then
force_all=true
fi
case "${GITHUB_REF:-}" in
refs/heads/darksky/np/mobile|refs/heads/canary|refs/heads/darksky/native-playground)
force_all=true
;;
esac
if [ "$force_all" != "true" ]; then
if [ "${GITHUB_EVENT_NAME:-}" = "pull_request" ] && [ -n "${PR_BASE_SHA:-}" ]; then
if ! git cat-file -e "${PR_BASE_SHA}^{commit}" 2>/dev/null; then
git fetch --no-tags --depth=50 origin "$PR_BASE_SHA" >/dev/null 2>&1 || true
fi
if git cat-file -e "${PR_BASE_SHA}^{commit}" 2>/dev/null; then
sha=$PR_BASE_SHA
fi
else
case "${GITHUB_REF_NAME:-}" in
darksky/np/mobile-*)
git fetch --no-tags --depth=50 origin darksky/np/mobile:refs/remotes/origin/darksky/np/mobile >/dev/null 2>&1 || true
git fetch --no-tags --depth=50 origin canary:refs/remotes/origin/canary >/dev/null 2>&1 || true
if git rev-parse --verify origin/darksky/np/mobile >/dev/null 2>&1; then
sha=$(git merge-base HEAD origin/darksky/np/mobile 2>/dev/null || true)
fi
if [ -z "$sha" ] && git rev-parse --verify origin/canary >/dev/null 2>&1; then
sha=$(git merge-base HEAD origin/canary 2>/dev/null || true)
fi
;;
*)
if [ -n "${BEFORE//0/}" ]; then
if ! git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then
git fetch --no-tags --depth=50 origin "$BEFORE" >/dev/null 2>&1 || true
fi
if git cat-file -e "${BEFORE}^{commit}" 2>/dev/null; then
sha=$BEFORE
fi
fi
if [ -z "$sha" ]; then
git fetch --no-tags --depth=50 origin darksky/np/mobile:refs/remotes/origin/darksky/np/mobile >/dev/null 2>&1 || true
git fetch --no-tags --depth=50 origin canary:refs/remotes/origin/canary >/dev/null 2>&1 || true
if git rev-parse --verify origin/darksky/np/mobile >/dev/null 2>&1; then
sha=$(git merge-base HEAD origin/darksky/np/mobile 2>/dev/null || true)
elif git rev-parse --verify origin/canary >/dev/null 2>&1; then
sha=$(git merge-base HEAD origin/canary 2>/dev/null || true)
fi
fi
;;
esac
fi
fi
if [ -z "$sha" ]; then
force_all=true
fi
echo "sha=$sha" >> "$GITHUB_OUTPUT"
echo "force_all=$force_all" >> "$GITHUB_OUTPUT"
- name: Classify web host and Desktop leaf changes
id: classify
env:
BASE: ${{ steps.base.outputs.sha }}
FORCE_ALL: ${{ steps.base.outputs.force_all }}
run: |
node scripts/ci/classify-web-host-only.mjs \
--base "$BASE" \
--force-all "$FORCE_ALL" \
--ref "$GITHUB_REF" \
--event "${GITHUB_EVENT_NAME:-}" \
--github-output "$GITHUB_OUTPUT"
mobile-gates-and-web:
name: L0, Invariants, Web Host & Preview Tests
needs: changes
if: needs.changes.outputs.backend-only != 'true'
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: L0 Tier A static gates
run: |
node scripts/ci/check-l0-tier-a.mjs
node --test scripts/ci/classify-web-host-only.test.mjs
- name: Web mobile thin host and perf comparator tests
working-directory: packages/frontend
run: |
node --test hosts/web/tests/*.test.mjs scripts/check-snapshot-prefixes.test.mjs
node hosts/web/scripts/verify-zero-third-party-js.mjs
node --test perf/compare-n3.test.mjs
- name: Install Linux fontconfig, Mesa Lavapipe Vulkan, and CJK fallback font
if: needs.changes.outputs.desktop-leaf-only != 'true'
run: |
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get update
sudo apt-get install -y --no-install-recommends mesa-vulkan-drivers libvulkan1 libfontconfig1-dev libfreetype-dev fonts-wqy-zenhei
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.98.1
with:
components: rustfmt, clippy
targets: wasm32-unknown-unknown
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
key: np-mobile-gates
shared-key: np-mobile-gates
- name: Format check
working-directory: packages/frontend
run: cargo fmt --all -- --check
- name: Clippy check
if: needs.changes.outputs.desktop-leaf-only != 'true'
working-directory: packages/frontend
run: cargo clippy --locked --workspace --all-targets --features harness -- -D warnings
- name: Host and preview tests
if: needs.changes.outputs.desktop-leaf-only != 'true'
working-directory: packages/frontend
run: cargo test --locked -p affine-android-host -p affine-ios-host -p blocksuite-preview --all-features
- name: Mobile tests
if: needs.changes.outputs.desktop-leaf-only != 'true'
working-directory: packages/frontend
run: cargo test --locked -p affine-mobile --all-targets
- name: Mobile harness audit matrix
if: needs.changes.outputs.desktop-leaf-only != 'true'
working-directory: packages/frontend
run: cargo run --locked -p affine-mobile --features harness --bin mobile-harness -- audit-matrix
- name: Mobile harness frame replay
if: needs.changes.outputs.desktop-leaf-only != 'true'
working-directory: packages/frontend
run: cargo run --locked -p affine-mobile --features harness --bin mobile-harness -- fps-replay
- name: Static invariants and link-flag check
working-directory: packages/frontend
run: ./scripts/check-invariants.sh
s1-probes-bench:
name: S1 Release Probes (SQLite, Mermaid, RaTeX, Hayro PDF)
needs: changes
if: >-
needs.changes.outputs.backend-only != 'true' &&
needs.changes.outputs.web-wrapper-only != 'true' &&
needs.changes.outputs.web-host-only != 'true' &&
needs.changes.outputs.desktop-leaf-only != 'true'
runs-on: ubuntu-24.04
timeout-minutes: 30
env:
CARGO_PROFILE_RELEASE_LTO: 'false'
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: '16'
CARGO_PROFILE_RELEASE_DEBUG: '0'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.98.1
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
key: np-mobile-s1-probes-v2
shared-key: np-mobile-s1-probes-v2
- name: Cache Noto CJK font
id: noto-cjk-cache
uses: actions/cache@v4
with:
path: ~/.cache/affine-s1-fonts
key: s1-noto-cjk-${{ runner.os }}-b76b0433203017ca
- name: Install Noto CJK font for 24-case Mermaid visual probes
run: |
NOTO_SHA256="b76b0433203017ca80401b2ee0dd69350349871c4b19d504c34dbdd80541690a"
NOTO_URL="https://github.com/notofonts/noto-cjk/raw/523d033d6cb47f4a80c58a35753646f5c3608a78/Sans/OTC/NotoSansCJK-Regular.ttc"
FONT_CACHE_DIR="$HOME/.cache/affine-s1-fonts"
FONT_CACHE_FILE="$FONT_CACHE_DIR/NotoSansCJK-Regular.ttc"
mkdir -p "$FONT_CACHE_DIR"
if ! echo "$NOTO_SHA256 $FONT_CACHE_FILE" | sha256sum -c - >/dev/null 2>&1; then
if ! curl -fsSL --retry 3 "$NOTO_URL" -o "$FONT_CACHE_FILE.tmp"; then
rm -f "$FONT_CACHE_FILE.tmp"
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get update
sudo apt-get install -y --no-install-recommends 'fonts-noto-cjk=1:20230817+repack1-3*'
FOUND_FONT=$(find /usr/share/fonts -name 'NotoSansCJK-Regular.ttc' -print -quit)
test -s "$FOUND_FONT"
cp -f "$FOUND_FONT" "$FONT_CACHE_FILE.tmp"
fi
mv -f "$FONT_CACHE_FILE.tmp" "$FONT_CACHE_FILE"
fi
echo "$NOTO_SHA256 $FONT_CACHE_FILE" | sha256sum -c -
sudo mkdir -p /usr/share/fonts/opentype/noto
sudo cp -f "$FONT_CACHE_FILE" /usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc
sudo fc-cache -f /usr/share/fonts/opentype/noto
fc-list | grep -qi "Noto Sans CJK"
echo "AFFINE_CJK_FONT=$FONT_CACHE_FILE" >> "$GITHUB_ENV"
- name: Run S1 release probes and validate artifacts
working-directory: packages/frontend
env:
AFFINE_S1_OUT_DIR: /tmp/s1-artifacts
run: |
test -s "$AFFINE_CJK_FONT"
rm -rf /tmp/s1-artifacts
mkdir -p /tmp/s1-artifacts
t0=$(date +%s)
CARGO_ENCODED_RUSTFLAGS="" cargo test --locked --release --no-run \
-p affine-store --test s1_sqlite_probe \
-p blocksuite-preview --test s1_probes
echo "Compile S1 release probes duration: $(( $(date +%s) - t0 ))s"
t0=$(date +%s)
CARGO_ENCODED_RUSTFLAGS="" cargo test --locked --release \
-p affine-store --test s1_sqlite_probe \
-p blocksuite-preview --test s1_probes \
-- --nocapture
echo "Run S1 release probes duration: $(( $(date +%s) - t0 ))s"
test -s /tmp/s1-artifacts/s1-sqlite-report.json
test -s /tmp/s1-artifacts/s1-probes-report.json
PNG_COUNT=$(find /tmp/s1-artifacts -maxdepth 1 -name 'mermaid-*.png' | wc -l | tr -d ' ')
echo "Generated Mermaid PNG count: $PNG_COUNT"
test "$PNG_COUNT" -eq 24
for theme in light dark; do
for name in flowchart sequence state class pie er gantt gitgraph wrapped-latin wrapped-cjk generic-class frontmatter; do
test -s "/tmp/s1-artifacts/mermaid-${theme}-${name}.png"
done
done
- name: Upload S1 probes report and rendered PNG artifacts
uses: actions/upload-artifact@v4
with:
name: s1-probes-artifacts
path: /tmp/s1-artifacts
if-no-files-found: error
preview-wasm-workers:
name: Preview Wasm Workers (4 Independent Targets)
needs: changes
if: >-
needs.changes.outputs.backend-only != 'true' &&
needs.changes.outputs.desktop-rs-only != 'true'
runs-on: ubuntu-24.04
timeout-minutes: 20
defaults:
run:
working-directory: packages/frontend
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.98.1
with:
targets: wasm32-unknown-unknown
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
key: np-mobile-preview-wasm
shared-key: np-mobile-preview-wasm
- name: Install wasm-bindgen CLI and Binaryen wasm-opt
run: |
WBG_VERSION=$(awk '/^name = "wasm-bindgen"$/{getline; gsub(/"/, "", $3); print $3; exit}' Cargo.lock)
URL="https://github.com/wasm-bindgen/wasm-bindgen/releases/download/${WBG_VERSION}/wasm-bindgen-${WBG_VERSION}-x86_64-unknown-linux-musl.tar.gz"
if curl -fsSL "$URL" | tar -xz -C /tmp; then
sudo install -m 0755 "/tmp/wasm-bindgen-${WBG_VERSION}-x86_64-unknown-linux-musl/wasm-bindgen" /usr/local/bin/wasm-bindgen
else
cargo install --locked wasm-bindgen-cli --version "$WBG_VERSION"
fi
wasm-bindgen --version
BINARYEN_VERSION="version_123"
BINARYEN_SHA256="e959f2170af4c20c552e9de3a0253704d6a9d2766e8fdb88e4d6ac4bae9388fe"
curl -fsSL "https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VERSION}/binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz" \
-o /tmp/binaryen.tar.gz
echo "${BINARYEN_SHA256} /tmp/binaryen.tar.gz" | sha256sum -c -
tar -xzf /tmp/binaryen.tar.gz -C /tmp
rm -f /tmp/binaryen.tar.gz
sudo install -m 0755 "/tmp/binaryen-${BINARYEN_VERSION}/bin/wasm-opt" /usr/local/bin/wasm-opt
wasm-opt --version
- name: Build and verify main playground Wasm bundle and 4 preview Wasm workers
run: |
mkdir -p /tmp/preview-wasm/pkg
REPO_ROOT="$(cd ../.. && pwd)"
CARGO_HOME_DIR="${CARGO_HOME:-$HOME/.cargo}"
WASM_RUSTFLAGS="$(printf '%s\037%s\037%s' "--remap-path-prefix=${REPO_ROOT}=/src" "--remap-path-prefix=${CARGO_HOME_DIR}=/cargo" "-Ctarget-feature=+simd128")"
work_dir=$(mktemp -d)
set -m
trap 'exit 1' USR1
trap 'for pid in $(jobs -pr); do kill -- "-$pid" 2>/dev/null || true; done; wait || true; rm -rf "$work_dir"' EXIT
kinds=(mermaid math typst pdf)
pids=()
optimize_wasm() {
wasm-opt -Oz --strip-debug --strip-producers \
--enable-bulk-memory \
--enable-nontrapping-float-to-int \
--enable-sign-ext \
--enable-mutable-globals \
--enable-simd "$1" -o "$2"
}
postprocess() (
local kind="$1"
shift
trap 'rc=$?; if [ "$rc" -ne 0 ]; then
printf "Wasm post-processing for %s failed (status %s)\n" "$kind" "$rc" >&3
cat "$work_dir/${kind}.log" >&3
kill -USR1 "$$"
fi' EXIT
"$@"
)
# Wait on Cargo so a failed optimizer can interrupt the build.
for kind in "${kinds[@]}"; do
CARGO_ENCODED_RUSTFLAGS="$WASM_RUSTFLAGS" cargo rustc --locked --target wasm32-unknown-unknown --profile wasm-worker-size -p blocksuite-preview --lib --crate-type cdylib --no-default-features --features "${kind},wasm-worker" &
wait "$!"
cp target/wasm32-unknown-unknown/wasm-worker-size/blocksuite_preview.wasm "$work_dir/${kind}.wasm"
postprocess "$kind" optimize_wasm "$work_dir/${kind}.wasm" "/tmp/preview-wasm/${kind}.wasm" 3>&2 > "$work_dir/${kind}.log" 2>&1 &
pids+=("$!")
done
CARGO_ENCODED_RUSTFLAGS="$WASM_RUSTFLAGS" cargo build --locked --profile wasm-release-size -p playground --lib --target wasm32-unknown-unknown &
wait "$!"
bindgen_playground() {
wasm-bindgen --target web --out-dir /tmp/preview-wasm/pkg target/wasm32-unknown-unknown/wasm-release-size/playground.wasm
optimize_wasm /tmp/preview-wasm/pkg/playground_bg.wasm /tmp/preview-wasm/pkg/playground_bg.opt.wasm
mv /tmp/preview-wasm/pkg/playground_bg.opt.wasm /tmp/preview-wasm/pkg/playground_bg.wasm
}
postprocess playground bindgen_playground 3>&2 > "$work_dir/playground.log" 2>&1 &
pids+=("$!")
kinds+=(playground)
for i in "${!pids[@]}"; do
wait "${pids[$i]}"
kind=${kinds[$i]}
echo "=== $kind Wasm post-processing ==="
cat "$work_dir/${kind}.log"
done
for kind in mermaid math typst pdf; do
test -s "/tmp/preview-wasm/${kind}.wasm"
done
test -s /tmp/preview-wasm/pkg/playground_bg.wasm
{
echo "### 5-Wasm Bundle Sizes (post wasm-opt -Oz)"
echo "| Artifact | Raw (bytes) | Raw (KB) | Gzip (bytes) | Gzip (KB) |"
echo "|---|---:|---:|---:|---:|"
for f in /tmp/preview-wasm/pkg/playground_bg.wasm /tmp/preview-wasm/mermaid.wasm /tmp/preview-wasm/math.wasm /tmp/preview-wasm/typst.wasm /tmp/preview-wasm/pdf.wasm; do
raw_b=$(wc -c < "$f" | tr -d ' ')
gz_b=$(gzip -c -9 "$f" | wc -c | tr -d ' ')
raw_kb=$(awk "BEGIN { printf \"%.1f\", $raw_b / 1024 }")
gz_kb=$(awk "BEGIN { printf \"%.1f\", $gz_b / 1024 }")
echo "| \`$(basename "$f")\` | ${raw_b} | ${raw_kb} KB | ${gz_b} | ${gz_kb} KB |"
done
} | tee -a "${GITHUB_STEP_SUMMARY:-/dev/null}"
node hosts/web/scripts/stage-preview-workers.mjs /tmp/preview-wasm dev-local
node hosts/web/scripts/verify-preview-workers-e2e.mjs
- name: Warm Chromium binary into OS page cache
run: |
CHROME_WARM_BIN=${CHROME_PATH:-${CHROME_BIN:-}}
if [ -z "$CHROME_WARM_BIN" ]; then
wrapper=
for bin in /usr/bin/google-chrome-stable /usr/bin/google-chrome /usr/bin/chromium /usr/bin/chromium-browser; do
[ -e "$bin" ] || continue
if [ "$(head -c 2 "$bin" 2>/dev/null)" = '#!' ]; then
wrapper=${wrapper:-$bin}
else
CHROME_WARM_BIN=$bin
break
fi
done
if [ -z "$CHROME_WARM_BIN" ] && [ -d "$HOME/.cache/ms-playwright" ]; then
CHROME_WARM_BIN=$(find "$HOME/.cache/ms-playwright" -name chrome -type f -print -quit)
fi
CHROME_WARM_BIN=${CHROME_WARM_BIN:-$wrapper}
fi
if [ -z "$CHROME_WARM_BIN" ] || [ ! -e "$CHROME_WARM_BIN" ]; then
echo "warning: skipping Chromium warm-up (no binary found)" >&2
exit 0
fi
WARM_PROFILE=$(mktemp -d "${TMPDIR:-/tmp}/np-chrome-warm.XXXXXX")
trap 'rm -rf "$WARM_PROFILE"' EXIT
status=0
timeout --kill-after=2s 20s "$CHROME_WARM_BIN" --headless=new --no-sandbox --disable-gpu --disable-dbus --disable-dev-shm-usage --user-data-dir="$WARM_PROFILE" --dump-dom about:blank >/dev/null || status=$?
rm -rf "$WARM_PROFILE"
trap - EXIT
if [ "$status" -ne 0 ]; then
echo "warning: Chromium warm-up exited with status $status; continuing to test harness" >&2
fi
- name: Verify real-browser IndexedDB storage and V1 Yjs extraction
run: node hosts/web/scripts/verify-idb-real-browser.mjs
- name: Verify real-browser S3-Web GPU recovery, selection menu, and lazy hayro PDF worker
run: node hosts/web/scripts/verify-s3-web-real-browser.mjs
- name: Verify real-browser Canary dual-shell staging, zero-empty-IDB guard, and crash fallback CRDT round-trip
run: node hosts/web/scripts/verify-canary-dual-shell-browser.mjs /tmp/preview-wasm
android-host:
name: Android Thin Host (NDK .so Link & kotlinc)
needs: changes
if: >-
needs.changes.outputs.backend-only != 'true' &&
needs.changes.outputs.web-wrapper-only != 'true' &&
needs.changes.outputs.web-host-only != 'true' &&
needs.changes.outputs.desktop-leaf-only != 'true'
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache Kotlin compiler archive
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/kotlin-compiler-2.1.20.zip
key: kotlinc-2.1.20-v1
- name: Install Kotlin compiler
run: |
archive="$RUNNER_TEMP/kotlin-compiler-2.1.20.zip"
checksum="a118197b0de55ffab2bc8d5cd03a5e39033cfb53383d6931bc761dec0784891a $archive"
if [ ! -f "$archive" ] || ! printf '%s\n' "$checksum" | sha256sum --check --status; then
curl -fsSL https://github.com/JetBrains/kotlin/releases/download/v2.1.20/kotlin-compiler-2.1.20.zip -o "$archive"
printf '%s\n' "$checksum" | sha256sum --check
fi
unzip -q "$archive" -d "$RUNNER_TEMP"
"$RUNNER_TEMP/kotlinc/bin/kotlinc" -version
echo "$RUNNER_TEMP/kotlinc/bin" >> "$GITHUB_PATH"
- name: Install Rust toolchain with Android target
uses: dtolnay/rust-toolchain@1.98.1
with:
targets: aarch64-linux-android
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
key: np-mobile-android-host
shared-key: np-mobile-android-host
- name: Install Linux fontconfig and freetype headers for host tests
run: |
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
sudo apt-get update
sudo apt-get install -y --no-install-recommends pkg-config libfontconfig1-dev libfreetype-dev
- name: Link Android NDK arm64-v8a .so binary
working-directory: packages/frontend
run: |
NDK_BIN="$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin"
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="$NDK_BIN/aarch64-linux-android24-clang"
export CC_aarch64_linux_android="$NDK_BIN/aarch64-linux-android24-clang"
export AR_aarch64_linux_android="$NDK_BIN/llvm-ar"
cargo build --locked -p affine-android-host --target aarch64-linux-android
SRC="target/aarch64-linux-android/debug/libaffine_android_host.so"
test -s "$SRC"
DST="/tmp/libaffine_android_host_aarch64-linux-android.stripped.so"
cp "$SRC" "$DST"
"$NDK_BIN/llvm-strip" --strip-unneeded "$DST"
BYTES=$(stat -c '%s' "$DST")
MAX_BYTES=165000000
echo "Stripped aarch64-linux-android libaffine_android_host.so bytes: ${BYTES} (max ${MAX_BYTES})"
test "$BYTES" -le "$MAX_BYTES"
- name: Compile Android thin host Kotlin sources with kotlinc and run real JNI parity check
run: |
ANDROID_JAR=$(ls -1 "$ANDROID_HOME"/platforms/android-*/android.jar | sort -V | tail -n 1)
echo "Using Android SDK jar: $ANDROID_JAR"
cargo build --locked --manifest-path packages/frontend/Cargo.toml -p affine-android-host --features host-jni
test -s packages/frontend/target/debug/libaffine_android_host.so
mkdir -p /tmp/affine-android-kotlin
kotlinc -classpath "$ANDROID_JAR" \
-d /tmp/affine-android-kotlin \
packages/frontend/hosts/android/kotlin/app/affine/pro/host/MainActivity.kt \
packages/frontend/hosts/android/kotlin/app/affine/pro/host/LegacyLocalStorageProbe.kt \
packages/frontend/hosts/android/kotlin/app/affine/pro/host/AndroidBootstrapCoordinator.kt \
packages/frontend/hosts/android/kotlin/app/affine/pro/host/AuthDataStore.kt \
packages/frontend/hosts/android/kotlin/app/affine/pro/host/ShareIntentBridge.kt \
packages/frontend/hosts/android/kotlin/app/affine/pro/host/ShareReceiverActivity.kt \
packages/frontend/hosts/android/tests/ImeHostParityCheck.kt
test -s /tmp/affine-android-kotlin/app/affine/pro/host/MainActivity.class
test -s /tmp/affine-android-kotlin/app/affine/pro/host/ShareReceiverActivity.class
test -s /tmp/affine-android-kotlin/app/affine/pro/host/AffineImeController.class
test -s /tmp/affine-android-kotlin/app/affine/pro/host/AffineInputConnection.class
test -s /tmp/affine-android-kotlin/app/affine/pro/host/LegacyLocalStorageProbe.class
test -s /tmp/affine-android-kotlin/app/affine/pro/host/AndroidBootstrapCoordinator.class
test -s /tmp/affine-android-kotlin/app/affine/pro/host/AuthSessionStore.class
test -s /tmp/affine-android-kotlin/app/affine/pro/host/AuthTokenCipher.class
kotlin -J-Djava.library.path="$PWD/packages/frontend/target/debug" \
-cp "/tmp/affine-android-kotlin:$ANDROID_JAR" \
ImeHostParityCheckKt
./packages/frontend/hosts/android/scripts/package-debug-apk.sh /tmp/android-apk
rm -rf /tmp/android-apk/work
sha256sum /tmp/android-apk/AffineAndroidHost-debug.apk | tee /tmp/android-apk/AffineAndroidHost-debug.apk.sha256
- name: Upload signed Android debug APK artifact
uses: actions/upload-artifact@v4
with:
name: android-debug-apk
path: |
/tmp/android-apk/AffineAndroidHost-debug.apk
/tmp/android-apk/AffineAndroidHost-debug.apk.sha256
if-no-files-found: error
ios-device-check:
name: iOS Device SDK Check (ui & affine-ios-host)
needs: changes
if: >-
needs.changes.outputs.backend-only != 'true' &&
needs.changes.outputs.web-wrapper-only != 'true' &&
needs.changes.outputs.web-host-only != 'true' &&
needs.changes.outputs.desktop-leaf-only != 'true' &&
needs.changes.outputs.apple-specific == 'true'
runs-on: macos-15
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain with iOS device target
uses: dtolnay/rust-toolchain@1.98.1
with:
targets: aarch64-apple-ios
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
shared-key: ios-device-check
key: np-mobile-ios-device-v1
- name: Check affine-ios-host and ui for iOS device target
working-directory: packages/frontend
env:
CARGO_PROFILE_DEV_DEBUG: '0'
CARGO_INCREMENTAL: '0'
run: cargo check --locked -p ui -p affine-ios-host --target aarch64-apple-ios
ios-host:
name: iOS Thin Host (Rust staticlib & Swift Simulator Link)
needs: changes
if: >-
needs.changes.outputs.backend-only != 'true' &&
needs.changes.outputs.web-wrapper-only != 'true' &&
needs.changes.outputs.web-host-only != 'true' &&
needs.changes.outputs.desktop-leaf-only != 'true' &&
needs.changes.outputs.apple-specific == 'true'
runs-on: macos-15
timeout-minutes: 20
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain with iOS Simulator target
uses: dtolnay/rust-toolchain@1.98.1
with:
targets: aarch64-apple-ios-sim
- name: Cache Cargo artifacts
uses: Swatinem/rust-cache@v2
with:
workspaces: packages/frontend -> target
shared-key: ios-sim-host
key: np-mobile-ios-host-v5
- name: Build the iOS staticlib and select a Simulator
working-directory: packages/frontend
env:
CARGO_PROFILE_DEV_DEBUG: '0'
CARGO_INCREMENTAL: '0'
shell: bash
run: bash hosts/ios/scripts/check-sim-host.sh
- name: Link zero-CocoaPods Swift iOS host and run 7/7 Simulator smoke tests
shell: bash
run: |
run_timed() {
local label="$1" started=$SECONDS rc=0
shift
echo "$(date -u +%FT%TZ) Start $label"
"$@" || rc=$?
echo "$(date -u +%FT%TZ) End $label after $(( SECONDS - started ))s (status $rc)"
return "$rc"
}
smoke_dir=$(mktemp -d "${RUNNER_TEMP:-/tmp}/ios-host.XXXXXXXX")
trap 'rm -rf "$smoke_dir"' EXIT
SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
SMOKE_SOURCES=()
for f in packages/frontend/hosts/ios/Sources/*.swift; do
case "$(basename "$f")" in
AppDelegate.swift|SceneDelegate.swift|main.swift) continue ;;
esac
SMOKE_SOURCES+=("$f")
done
swift_flags=(
-emit-executable
-sdk "$SDK"
-target arm64-apple-ios16.0-simulator
-import-objc-header packages/frontend/hosts/ios/include/affine_mobile_host.h
-L packages/frontend/target/aarch64-apple-ios-sim/debug
-laffine_ios_host
-framework UIKit
-framework QuartzCore
-framework Metal
-framework WebKit
-framework PDFKit
-framework CoreText
-framework CoreGraphics
-framework CoreVideo
-framework CoreFoundation
-framework Foundation
-framework UniformTypeIdentifiers
-framework StoreKit
-framework AuthenticationServices
)
prepare_simulator() {
local boot_output boot_rc=0
case "$SIM_STATE" in
Shutdown)
boot_output=$(xcrun simctl boot "$SIM_UDID" 2>&1) || boot_rc=$?
if [ "$boot_rc" -ne 0 ]; then
printf '%s\n' "$boot_output" >&2
if ! grep -Exq 'Unable to boot device in current state: (Booted|Booting)' <<< "$boot_output"; then
return "$boot_rc"
fi
fi
;;
Booted|Booting) ;;
*) echo "Unexpected Simulator state $SIM_STATE for $SIM_UDID" >&2; return 1 ;;
esac
xcrun simctl bootstatus "$SIM_UDID" -b || return $?
echo "$(date -u +%FT%TZ) Simulator ready: $SIM_UDID"
}
# Each task reports when it finishes so failures appear in completion order.
mkfifo "$smoke_dir/completed"
exec 3<>"$smoke_dir/completed"
run_parallel() {
set +m
local label="$1" started=$SECONDS rc=0
run_timed "$@" > "$smoke_dir/$label.log" 2>&1 || rc=$?
printf '%s %s\n' "$label" "$(( SECONDS - started ))" >&3
return "$rc"
}
# Give each task a process group so cancellation reaches its child processes.
set -m
run_parallel AffineIosHost swiftc "${swift_flags[@]}" \
-o "$smoke_dir/AffineIosHost" packages/frontend/hosts/ios/Sources/*.swift &
host_pid=$!
run_parallel IosHostS3SmokeTest swiftc "${swift_flags[@]}" \
-o "$smoke_dir/IosHostS3SmokeTest" "${SMOKE_SOURCES[@]}" \
packages/frontend/hosts/ios/tests/IosHostS3SmokeTest.swift &
smoke_link_pid=$!
run_parallel Simulator prepare_simulator &
simulator_pid=$!
set +m
parallel_rc=0
swift_s=0
for _ in 1 2 3; do
read -r label elapsed <&3
case "$label" in
AffineIosHost) pid=$host_pid ;;
IosHostS3SmokeTest) pid=$smoke_link_pid ;;
Simulator)
pid=$simulator_pid
echo "sim_boot_s=$elapsed"
;;
esac
if [[ "$label" != Simulator && "$elapsed" -gt "$swift_s" ]]; then
swift_s=$elapsed
fi
rc=0
wait "$pid" || rc=$?
cat "$smoke_dir/$label.log"
if [ "$rc" -ne 0 ]; then
echo "::error::$label failed with status $rc"
parallel_rc=$rc
break
fi
done
exec 3>&-
if [ "$parallel_rc" -ne 0 ]; then
task_groups=("-$host_pid" "-$smoke_link_pid" "-$simulator_pid")
kill -TERM -- "${task_groups[@]}" 2>/dev/null || true
sleep 0.1
kill -KILL -- "${task_groups[@]}" 2>/dev/null || true
wait "$host_pid" "$smoke_link_pid" "$simulator_pid" || true
exit "$parallel_rc"
fi
echo "swift_s=$swift_s"
test -s "$smoke_dir/AffineIosHost"
test -s "$smoke_dir/IosHostS3SmokeTest"
echo "Running iOS smoke tests on Simulator UDID: $SIM_UDID"
smoke_started=$SECONDS
if run_timed "Seven iOS smoke tests" env SIMCTL_CHILD_NSUnbufferedIO=YES \
xcrun simctl spawn "$SIM_UDID" "$smoke_dir/IosHostS3SmokeTest"; then
echo "smoke_s=$(( SECONDS - smoke_started ))"
echo "$(date -u +%FT%TZ) Seven iOS smoke tests passed"
else
rc=$?
echo "smoke_s=$(( SECONDS - smoke_started ))"
echo "::warning::IosHostS3SmokeTest exited with status $rc; collecting last 2m Simulator WebKit logs" >&2
perl -e 'alarm 15; exec @ARGV' -- xcrun simctl spawn "$SIM_UDID" log show \
--last 2m \
--style compact \
--predicate 'subsystem BEGINSWITH "com.apple.WebKit" OR process CONTAINS "WebContent" OR process CONTAINS "Networking" OR process CONTAINS "IosHostS3SmokeTest"' \
2>&1 | tail -n 200 >&2 || true
exit "$rc"
fi
- name: Shutdown iOS Simulator
if: always() && env.SIM_UDID != ''
timeout-minutes: 1
continue-on-error: true
run: |
echo "$(date -u +%FT%TZ) Shut down Simulator $SIM_UDID"
xcrun simctl shutdown "$SIM_UDID"
echo "$(date -u +%FT%TZ) Simulator shut down"
- name: Remove iOS host archives before cache save
working-directory: packages/frontend/target/aarch64-apple-ios-sim/debug
run: rm -f libaffine_ios_host.a deps/libaffine_ios_host*