Files
client/.gitea/workflows/android.yml
T
2026-11-14 18:33:17 +03:00

339 lines
18 KiB
YAML

# Trusted mobile-branch pushes only; never execute fork pull requests on the shared runner.
# Installs occur only inside the disposable Ubuntu container. No releases or phone actions.
name: android-ci
on:
push:
branches: [feature/mobile-port]
workflow_dispatch:
inputs:
mode:
description: Build the test APK, or inspect resources only
required: true
default: build
type: choice
options: [build, inventory]
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
android-arm64:
runs-on: ubuntu-latest
container:
image: ubuntu:24.04
timeout-minutes: 360
env:
TARGET: aarch64-linux-android
EXPECTED_REVISION: ${{ github.sha }}
CI_RUN_ID: ${{ github.run_id }}
ANDROID_CI_PROVISION: container
CARGO_TERM_COLOR: never
TEAMSPEACH_ANDROID_LOW_MEMORY: "false"
CARGO_TARGET_DIR: ${{ github.workspace }}/.android-ci/cargo-target
steps:
- name: Resource gate before checkout, cache restore or tool installation
id: resources
run: |
set -euo pipefail
test "$(uname -s)" = Linux
test "$(uname -m)" = x86_64
test -f /.dockerenv
printf 'Architecture: '; uname -m
printf 'CPU count: '; getconf _NPROCESSORS_ONLN
df -Pk . /
while IFS=: read -r key value; do
case "$key" in MemTotal|MemAvailable) printf '%s:%s\n' "$key" "$value" ;; esac
done < /proc/meminfo
if [ '${{ github.event.inputs.mode }}' = inventory ]; then exit 0; fi
for path in . /; do
free=$(df --output=avail -B1 "$path")
free=${free##*$'\n'}
if ! [[ "$free" =~ ^[[:space:]]*[0-9]+[[:space:]]*$ ]] || (( free < 107374182400 )); then
echo "BLOCKED: Android cold source build requires 100 GiB free on workspace and container root; no tools installed. Ask runner administrator for build storage."
exit 1
fi
done
available=0
while read -r key value unit; do if [ "$key" = MemAvailable: ]; then available=$value; fi; done < /proc/meminfo
if (( available < 8388608 )); then echo 'BLOCKED: at least 8 GiB available RAM required'; exit 1; fi
jobs=$(nproc)
[[ "$jobs" =~ ^[1-9][0-9]*$ ]] || { echo 'Cannot determine available runner CPUs'; exit 1; }
printf 'Using all available runner CPUs: %s Cargo/Ninja/CMake jobs\n' "$jobs"
printf 'CARGO_BUILD_JOBS=%s\nCMAKE_BUILD_PARALLEL_LEVEL=%s\n' "$jobs" "$jobs" >> "$GITHUB_ENV"
- name: Bootstrap utilities inside the disposable job container
if: ${{ github.event.inputs.mode != 'inventory' }}
run: |
set -euo pipefail
test -f /.dockerenv
test "$(id -u)" = 0
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y --no-install-recommends ca-certificates git nodejs python3 zstd
- uses: actions/checkout@v4
if: ${{ github.event.inputs.mode != 'inventory' }}
with:
clean: true
persist-credentials: false
# Keep provisioned tools/registry sources separate from completed Cargo outputs.
- name: Restore isolated tool and Cargo source cache
if: ${{ github.event.inputs.mode != 'inventory' }}
id: cache
uses: actions/cache/restore@v3
with:
path: |
.android-ci/tools/downloads
.android-ci/tools/rustup
.android-ci/tools/cargo
.android-ci/tools/android-sdk
.android-ci/tools/skia-m153-0.101.2
.android-ci/tools/gradle
# Lock changes may need new registry sources, not a new SDK/toolchain.
# v3 starts one cold generation: v2 has no independently verifiable tool contract.
key: android-tools-linux-x64-arm64-v3-${{ hashFiles('.gitea/android-ci-tools.json', '.gitea/setup-android-ci.sh', 'rust-toolchain.toml', 'platform/android/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('Cargo.lock') }}-${{ github.sha }}-${{ github.run_id }}
restore-keys: |
android-tools-linux-x64-arm64-v3-${{ hashFiles('.gitea/android-ci-tools.json', '.gitea/setup-android-ci.sh', 'rust-toolchain.toml', 'platform/android/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('Cargo.lock') }}-
android-tools-linux-x64-arm64-v3-${{ hashFiles('.gitea/android-ci-tools.json', '.gitea/setup-android-ci.sh', 'rust-toolchain.toml', 'platform/android/gradle/wrapper/gradle-wrapper.properties') }}-
- name: Provision pinned Android tools in the job container
if: ${{ github.event.inputs.mode != 'inventory' }}
id: tools
run: bash .gitea/setup-android-ci.sh
# Setup publishes the pinned environment before compatibility is computed.
# Never cross the opaque v1 application identity: one cold v2 generation.
- name: Compute isolated application cache identity
if: ${{ github.event.inputs.mode != 'inventory' }}
id: application-key
run: python3 .gitea/android-application-cache.py key
- name: Restore completed application compilation
if: ${{ github.event.inputs.mode != 'inventory' }}
id: application-cache
uses: actions/cache/restore@v3
with:
path: |
.android-ci/cargo-target
.android-ci/application-cache-inputs.json
key: ${{ steps.application-key.outputs.key }}-${{ github.sha }}-${{ github.run_id }}
restore-keys: |
${{ steps.application-key.outputs.key }}-${{ github.sha }}-
${{ steps.application-key.outputs.key }}-
${{ steps.application-key.outputs.previous-parallelism-key }}-
- name: Restore timestamps only for content-matched Cargo source inputs
if: ${{ github.event.inputs.mode != 'inventory' }}
run: python3 .gitea/android-application-cache.py sources
- name: Require exact revision and no production signing
if: ${{ github.event.inputs.mode != 'inventory' }}
run: |
set -euo pipefail
test "$(git rev-parse HEAD)" = "$EXPECTED_REVISION"
test ! -e dist/android
for name in TEAMSPEACH_ANDROID_KEYSTORE TEAMSPEACH_ANDROID_STORE_PASSWORD TEAMSPEACH_ANDROID_KEY_ALIAS TEAMSPEACH_ANDROID_KEY_PASSWORD; do
if [[ -v "$name" ]]; then echo 'Production signing environment forbidden in test CI'; exit 1; fi
done
cargo run --locked -p xtask -- check-version
cargo test --locked -p xtask
- name: Compute source dependency cache identity
if: ${{ github.event.inputs.mode != 'inventory' }}
id: dependency-key
run: |
python3 - <<'PY'
import hashlib, json, os, pathlib
policy = json.loads(pathlib.Path('native/native-deps.lock.json').read_text())
policy.pop('builds', None)
digest = hashlib.sha256(json.dumps(policy, sort_keys=True, separators=(',', ':')).encode())
for name in ('.gitea/android-ci-tools.json', 'xtask/src/deps.rs', 'xtask/src/build_native.rs'):
digest.update(name.encode() + b'\0' + pathlib.Path(name).read_bytes())
with open(os.environ['GITHUB_OUTPUT'], 'a') as out:
out.write('key=android-webrtc-linux-arm64-v1-' + digest.hexdigest() + '\n')
PY
- name: Restore pinned WebRTC source and object checkpoint
if: ${{ github.event.inputs.mode != 'inventory' }}
id: webrtc-cache
uses: actions/cache/restore@v3
with:
path: target/native-deps/aarch64-linux-android
key: ${{ steps.dependency-key.outputs.key }}
# Source provenance is regenerated and verified, never trusted from an Actions cache.
- name: Build pinned WebRTC dependencies with bounded CI parallelism
if: ${{ github.event.inputs.mode != 'inventory' }}
id: dependencies
run: |
set -euo pipefail
python3 .gitea/prepare-android-dependency-cache.py
cargo run --locked -p xtask -- deps --target "$TARGET" --llvm-dir "$LLVM_HOME" --jobs "$CARGO_BUILD_JOBS"
python3 .gitea/android-application-cache.py dependencies
- name: Checkpoint verified WebRTC before application build
if: ${{ success() && github.event.inputs.mode != 'inventory' && steps.webrtc-cache.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v3
with:
path: target/native-deps/aarch64-linux-android
key: ${{ steps.dependency-key.outputs.key }}
- name: Checkpoint provisioned tools before application build
if: ${{ success() && github.event.inputs.mode != 'inventory' && steps.cache.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v3
with:
path: |
.android-ci/tools/downloads
.android-ci/tools/rustup
.android-ci/tools/cargo
.android-ci/tools/android-sdk
.android-ci/tools/skia-m153-0.101.2
.android-ci/tools/gradle
key: ${{ steps.cache.outputs.cache-primary-key }}-checkpoint
# Host tests use neither Android artifacts nor Skia/WebRTC. The APK below keeps all features.
- name: Install Linux host audio test prerequisites in container
if: ${{ github.event.inputs.mode != 'inventory' }}
run: |
set -euo pipefail
test -f /.dockerenv
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y --no-install-recommends libpipewire-0.3-dev libspa-0.2-dev libxkbcommon-x11-dev libxcb-shape0-dev libxcb-xfixes0-dev
- name: Restore isolated Linux audio test compilation
if: ${{ github.event.inputs.mode != 'inventory' }}
id: audio-test-cache
uses: actions/cache/restore@v3
with:
path: .android-ci/host-audio-target
key: host-audio-linux-x64-v1-${{ hashFiles('rust-toolchain.toml', 'Cargo.lock', '.cargo/config.toml', '.gitea/workflows/android.yml') }}-${{ github.sha }}-${{ github.run_id }}
restore-keys: |
host-audio-linux-x64-v1-${{ hashFiles('rust-toolchain.toml', 'Cargo.lock', '.cargo/config.toml', '.gitea/workflows/android.yml') }}-
- name: Run actual native audio worker and capture authorization regressions
if: ${{ github.event.inputs.mode != 'inventory' }}
id: audio-tests
env:
CARGO_TARGET_DIR: ${{ github.workspace }}/.android-ci/host-audio-target
CARGO_PROFILE_TEST_OPT_LEVEL: "1"
CARGO_PROFILE_TEST_DEBUG: "0"
run: |
set -euo pipefail
unset RUSTC_WORKSPACE_WRAPPER
mkdir -p .android-ci/audio-test-results
{
printf 'Revision: %s\nHost: x86_64-unknown-linux-gnu\nFeatures: no-default-features (test binary only)\n' "$EXPECTED_REVISION"
rustc --edition=2021 --test native/vendor/cpal-0.18.2/src/host/aaudio/device_catalog.rs -o .android-ci/audio-test-results/device-catalog-tests
.android-ci/audio-test-results/device-catalog-tests --test-threads=1
rustc --edition=2021 --test native/vendor/cpal-0.18.2/src/host/aaudio/capture_timing.rs -o .android-ci/audio-test-results/capture-timing-tests
.android-ci/audio-test-results/capture-timing-tests --test-threads=1
rustc --edition=2021 --test native/vendor/cpal-0.18.2/src/host/aaudio/output_usage.rs -o .android-ci/audio-test-results/output-usage-tests
.android-ci/audio-test-results/output-usage-tests --test-threads=1
printf '#[path = "%s/native/src/platform/android/call_audio.rs"] mod call_audio;\n' "$GITHUB_WORKSPACE" > .android-ci/audio-test-results/call-audio-check.rs
rustc --edition=2021 --test .android-ci/audio-test-results/call-audio-check.rs -o .android-ci/audio-test-results/call-audio-tests
.android-ci/audio-test-results/call-audio-tests --test-threads=1
mkdir -p .android-ci/audio-test-results/java
javac -d .android-ci/audio-test-results/java platform/android/src/main/java/dev/teamspeach/mobile/CommunicationRoutePolicy.java platform/android/src/test/java/dev/teamspeach/mobile/CommunicationRoutePolicyTest.java
java -cp .android-ci/audio-test-results/java dev.teamspeach.mobile.CommunicationRoutePolicyTest
cargo test --locked -p teamspeach-denoise --target x86_64-unknown-linux-gnu --lib capture::tests --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
cargo test --locked -p teamspeach-native --no-default-features --target x86_64-unknown-linux-gnu --lib media::audio:: --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
cargo test --locked -p teamspeach-native --no-default-features --target x86_64-unknown-linux-gnu --lib capture_transition_tests --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
cargo test --locked -p teamspeach-native --no-default-features --target x86_64-unknown-linux-gnu --lib audit_lifecycle --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
cargo test --locked -p teamspeach-native --no-default-features --target x86_64-unknown-linux-gnu --lib only_explicit_output_device_actions_request_platform_routing --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
cargo test --locked -p teamspeach-native --no-default-features --target x86_64-unknown-linux-gnu --lib android_attachment_ --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
cargo test --locked -p teamspeach-native --no-default-features --target x86_64-unknown-linux-gnu --lib app::connections::tests --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
cargo test --locked -p teamspeach-core --target x86_64-unknown-linux-gnu --lib audio::tests --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
cargo test --locked -p teamspeach-core --target x86_64-unknown-linux-gnu --lib output::tests --jobs "$CARGO_BUILD_JOBS" -- --test-threads=1
} 2>&1 | tee .android-ci/audio-test-results/tests.log
- name: Save successful Linux audio test compilation
if: ${{ success() && steps.audio-tests.outcome == 'success' && steps.audio-test-cache.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v3
with:
path: .android-ci/host-audio-target
key: ${{ steps.audio-test-cache.outputs.cache-primary-key }}
- name: Retain actual host audio test results
if: ${{ always() && steps.audio-tests.outcome != 'skipped' && github.event.inputs.mode != 'inventory' }}
uses: actions/upload-artifact@v3
with:
name: native-audio-tests-linux-x64-${{ github.sha }}
path: .android-ci/audio-test-results/tests.log
if-no-files-found: warn
retention-days: 14
- name: Build and verify full-feature test APK
if: ${{ github.event.inputs.mode != 'inventory' }}
id: application-build
run: |
set -euo pipefail
unset RUSTC_WORKSPACE_WRAPPER
mkdir -p .android-ci/diagnostics
bash .gitea/android-memory-report.sh | tee .android-ci/diagnostics/before.txt
trap 'status=$?; trap - EXIT; bash .gitea/android-memory-report.sh | tee .android-ci/diagnostics/after.txt; exit "$status"' EXIT
/usr/bin/time -v -o .android-ci/diagnostics/build-time.txt bash .gitea/build-android-variant.sh harness
# Save immediately after compilation/package verification, not after uploads.
# always()+outcome also checkpoints a successful APK if later diagnostics fail.
- name: Record stable inputs of the completed application build
if: ${{ always() && steps.application-build.outcome == 'success' && github.event.inputs.mode != 'inventory' }}
id: application-snapshot
run: python3 .gitea/android-application-cache.py snapshot
- name: Save completed application compilation
if: ${{ always() && steps.application-snapshot.outcome == 'success' && steps.application-cache.outputs.cache-hit != 'true' && github.event.inputs.mode != 'inventory' }}
uses: actions/cache/save@v3
with:
path: |
.android-ci/cargo-target
.android-ci/application-cache-inputs.json
key: ${{ steps.application-cache.outputs.cache-primary-key }}
- name: Report container memory evidence on build failure
if: ${{ always() && steps.tools.outcome == 'success' && github.event.inputs.mode != 'inventory' }}
run: |
set -eu
if [ -f .android-ci/diagnostics/build-time.txt ]; then cat .android-ci/diagnostics/build-time.txt; fi
bash .gitea/android-memory-report.sh
- name: Retain native compiler resource diagnostics
if: ${{ always() && steps.tools.outcome == 'success' && github.event.inputs.mode != 'inventory' }}
uses: actions/upload-artifact@v3
with:
name: android-build-resources-${{ github.sha }}
path: .android-ci/diagnostics/*.txt
if-no-files-found: warn
retention-days: 7
- name: Upload installable Android test APK and provenance
if: ${{ github.event.inputs.mode != 'inventory' }}
uses: actions/upload-artifact@v3
with:
name: android-harness-arm64-${{ github.sha }}
path: |
dist/android/harness/*-harness-test.apk
dist/android/harness/build-info.json
dist/android/harness/aarch64-linux-android/*.json
if-no-files-found: error
retention-days: 14
- name: Save populated tool and Cargo source cache
if: ${{ always() && steps.application-build.outcome == 'success' && github.event.inputs.mode != 'inventory' && steps.cache.outputs.cache-hit != 'true' }}
uses: actions/cache/save@v3
with:
path: |
.android-ci/tools/downloads
.android-ci/tools/rustup
.android-ci/tools/cargo
.android-ci/tools/android-sdk
.android-ci/tools/skia-m153-0.101.2
.android-ci/tools/gradle
key: ${{ steps.cache.outputs.cache-primary-key }}