// The OxygenHub Android app's pipeline (OxygenFlow, #19). Every push runs
// the unit tests with coverage and a debug build in OxygenFlow's Android
// image, with no network: the JDK, the Android SDK and NDK, Gradle,
// cargo-ndk, rust-core's crates and the app's Gradle dependencies are all
// in the image (oxygenflow/images/android). Rebuild and re-pin it when the
// app's SDK, Gradle or dependency versions change, or rust-core's
// Cargo.lock does. Locally, ./gradlew :app:createDebugUnitTestCoverageReport
// runs the same tests.
schema-version 1

sandbox "android" {
    runtime "microvm"
    rootfs "cas://blob/6605d6c0b87e32667bb0b19ec473e76e7139a9f1cfa6cb36a03e773eee5af06c"
    memory-limit "8GiB"
    cpu-limit 4
    network "isolated"
    // Gradle reads dependencies from the image's read-only cache and
    // writes its own state under /tmp.
    env {
        ANDROID_HOME "/opt/android-sdk"
        JAVA_HOME "/usr/lib/jvm/java-17-openjdk-amd64"
        GRADLE_RO_DEP_CACHE "/opt/gradle-home/caches"
        GRADLE_USER_HOME "/tmp/gradle"
        CARGO_INCREMENTAL "0"
    }
}

job "test" {
    sandbox "android"
    timeout "60m"
    // rust-core (with oxy-core and the runner) for two ABIs is most of the
    // build: kept from the last passing run, so only what changed builds.
    mount {
        source "ephemeral://disk"
        target "/src/rust-core/target"
        size "20GiB"
        cache "rust-core-target"
        key "rust-core/Cargo.lock"
    }
    exec "bash" "scripts/ci.sh"
    output {
        artifact "junit" {
            path "/src/junit.xml"
            when "always"
        }
        artifact "coverage" {
            path "/src/coverage.xml"
            when "always"
        }
    }
}
