diff --git a/.buildkite/commands/connected-tests.sh b/.buildkite/commands/connected-tests.sh index 2fc465dbf..14eb1501e 100644 --- a/.buildkite/commands/connected-tests.sh +++ b/.buildkite/commands/connected-tests.sh @@ -1,21 +1,56 @@ -#!/bin/bash +#!/usr/bin/env bash set -euo pipefail -echo "--- :closed_lock_with_key: Installing Secrets" -./gradlew applyConfiguration +SYSTEM_IMAGE="system-images;android-34;google_apis;x86_64" +AVD_NAME="aztec-connected-tests" +EMULATOR_LOG="build/emulator.log" -echo -e "\n--- :gcloud: Logging into Google Cloud" -gcloud auth activate-service-account --key-file .configure-files/firebase.secrets.json +BUILD_SDK="$ANDROID_HOME" +# The agent user cannot write to the image's SDK, and Gradle still needs it. +EMULATOR_SDK="$(mktemp -d)" +ln -s "$BUILD_SDK/licenses" "$EMULATOR_SDK/licenses" +ln -s "$BUILD_SDK/platform-tools" "$EMULATOR_SDK/platform-tools" +ln -s "$BUILD_SDK/platforms" "$EMULATOR_SDK/platforms" +export ANDROID_HOME="$EMULATOR_SDK" +export ANDROID_SDK_ROOT="$EMULATOR_SDK" +export PATH="$EMULATOR_SDK/cmdline-tools/latest/bin:$EMULATOR_SDK/emulator:$EMULATOR_SDK/platform-tools:$PATH" -echo -e "\n--- :hammer_and_wrench: Building Tests" -./gradlew --stacktrace app:assembleDebug app:assembleDebugAndroidTest +stop_emulator() { + adb emu kill || true + avdmanager delete avd --name "$AVD_NAME" || true + rm -rf "$EMULATOR_SDK" +} -echo -e "\n--- :firebase: Run Tests" -gcloud firebase test android run \ - --project api-project-108380595987 \ - --type instrumentation \ - --app app/build/outputs/apk/debug/app-debug.apk \ - --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk \ - --device model=Nexus5X,version=26,locale=en,orientation=portrait \ - --verbosity info +echo "--- :package: Installing emulator and system image" +# `avdmanager` resolves the SDK from its own location, ignoring `ANDROID_HOME`, so it has to live in this SDK too. +sdkmanager --sdk_root="$EMULATOR_SDK" "cmdline-tools;latest" "emulator" "$SYSTEM_IMAGE" > /dev/null + +# The image lacks this library, and the emulator segfaults without it, even with `-no-window`. +EMULATOR_LIBS="$EMULATOR_SDK/extra-libs" +mkdir -p "$EMULATOR_LIBS" +dnf download --destdir "$EMULATOR_LIBS" libX11-xcb > /dev/null +rpm2cpio "$EMULATOR_LIBS"/*.rpm | (cd "$EMULATOR_LIBS" && cpio -idm --quiet) + +echo "--- :mag: Checking hardware acceleration" +ls -la /dev/kvm +emulator -accel-check + +echo "--- :robot_face: Starting Android emulator" +avdmanager create avd --force --name "$AVD_NAME" --package "$SYSTEM_IMAGE" --device "pixel_5" <<< "no" +trap stop_emulator EXIT + +mkdir -p "$(dirname "$EMULATOR_LOG")" +LD_LIBRARY_PATH="$EMULATOR_LIBS/usr/lib64" emulator -avd "$AVD_NAME" -no-window -no-audio -no-boot-anim -no-snapshot -no-metrics -gpu swiftshader_indirect > "$EMULATOR_LOG" 2>&1 & + +timeout 300 adb wait-for-device +timeout 300 bash -c 'until [[ "$(adb shell getprop sys.boot_completed 2> /dev/null | tr -d "\r")" == "1" ]]; do sleep 5; done' + +adb shell settings put global window_animation_scale 0 +adb shell settings put global transition_animation_scale 0 +adb shell settings put global animator_duration_scale 0 +adb shell settings put secure long_press_timeout 1800 +adb shell input keyevent 82 + +echo "--- :android: Running connected tests" +ANDROID_HOME="$BUILD_SDK" ANDROID_SDK_ROOT="$BUILD_SDK" ./gradlew --stacktrace :app:connectedDebugAndroidTest diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index df142f5ba..f452c0240 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -33,7 +33,9 @@ steps: command: .buildkite/commands/connected-tests.sh plugins: [$CI_TOOLKIT] artifact_paths: - - "aztec/build/test-results/**/*.xml" + - "app/build/reports/androidTests/connected/**/*" + - "app/build/outputs/androidTest-results/connected/**/*" + - "build/emulator.log" - label: "Publish :aztec" key: "publish-aztec" diff --git a/.configure b/.configure deleted file mode 100644 index d0982ba4d..000000000 --- a/.configure +++ /dev/null @@ -1,11 +0,0 @@ -{ - "project_name": "aztec-android", - "branch": "trunk", - "pinned_hash": "f1a61c572902401898e7e1c060b86d9da7baf8fa", - "files_to_copy": [ - { - "file": "android/WPAndroid/firebase.secrets.json", - "destination": ".configure-files/firebase.secrets.json" - } - ] -} \ No newline at end of file diff --git a/.configure-files/firebase.secrets.json.enc b/.configure-files/firebase.secrets.json.enc deleted file mode 100644 index 77ba472e3..000000000 Binary files a/.configure-files/firebase.secrets.json.enc and /dev/null differ diff --git a/.gitignore b/.gitignore index 38e2f5750..f29bdb4b7 100644 --- a/.gitignore +++ b/.gitignore @@ -53,13 +53,3 @@ ktlint # Dependencies vendor - -# Currently, the configure tool stores the encrypted files under -# .configure-files. Everything in that folder without a .enc extension should -# be ignored. -.configure-files/* -!.configure-files/*.enc - -# Secrets files that should never be committed, regardless of location -firebase.secrets.json - diff --git a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/BaseTest.kt b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/BaseTest.kt index df840aac5..0ee9d62f3 100644 --- a/app/src/androidTest/kotlin/org/wordpress/aztec/demo/BaseTest.kt +++ b/app/src/androidTest/kotlin/org/wordpress/aztec/demo/BaseTest.kt @@ -2,6 +2,7 @@ package org.wordpress.aztec.demo +import android.os.Build import android.util.Log import androidx.test.rule.GrantPermissionRule import androidx.test.runner.AndroidJUnit4 @@ -12,8 +13,11 @@ import org.junit.runner.RunWith abstract class BaseTest { @Rule @JvmField - val grantPermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.CAMERA, - android.Manifest.permission.WRITE_EXTERNAL_STORAGE) + val grantPermissionRule: GrantPermissionRule = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) { + GrantPermissionRule.grant(android.Manifest.permission.CAMERA) + } else { + GrantPermissionRule.grant(android.Manifest.permission.CAMERA, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) + } companion object { fun label(label: String) { diff --git a/build.gradle b/build.gradle index 878b2e1c2..b697472d6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,5 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -buildscript { - repositories { - maven { url "https://a8c-libs.s3.amazonaws.com/android" } - } - dependencies { - classpath 'com.automattic.android:configure:0.6.5' - } -} - plugins { id "com.android.application" apply false id "org.jetbrains.kotlin.android" apply false @@ -35,8 +26,6 @@ allprojects { } } -apply plugin: 'com.automattic.android.configure' - task clean(type: Delete) { delete rootProject.buildDir }