From 02d2aa79196089af2d41749cc395f551340ed9d4 Mon Sep 17 00:00:00 2001 From: "Xavier F. Gouchet" Date: Wed, 24 Jul 2024 15:06:56 +0200 Subject: [PATCH] RUM-483 use macos runner --- .gitlab-ci.yml | 78 +++++++++++++++++++++++++++++++++++- android-wait-for-emulator.sh | 25 ++++++++++++ buildSrc/build.gradle.kts | 3 ++ gradle.properties | 3 ++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100755 android-wait-for-emulator.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ff6645b281..1d8c33ee16 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,6 +17,11 @@ variables: KUBERNETES_MEMORY_REQUEST: "8Gi" KUBERNETES_MEMORY_LIMIT: "16Gi" + EMULATOR_NAME: "android_emulator" + ANDROID_ARCH: "arm64-v8a" + ANDROID_API: "34" + ANDROID_SDK_VERSION: "commandlinetools-mac-11076708_latest" + stages: - ci-image - security @@ -26,6 +31,34 @@ stages: - publish - notify +.snippets: + install-android-sdk: + - curl -sSL -o commandlinetools.zip https://dl.google.com/android/repository/$ANDROID_SDK_VERSION.zip + - rm -rf ~/android_sdk + - rm -rf ~/cmdline-tools + - unzip -q commandlinetools -d ~/ + - mkdir -p ~/android_sdk/cmdline-tools/latest + - mv ~/cmdline-tools/* ~/android_sdk/cmdline-tools/latest + - rm ./commandlinetools.zip + - export ANDROID_HOME="$HOME/android_sdk/" + - export ANDROID_SDK_ROOT="$HOME/android_sdk/" + - echo y | ~/android_sdk/cmdline-tools/latest/bin/sdkmanager --install "emulator" + - echo y | ~/android_sdk/cmdline-tools/latest/bin/sdkmanager --install "platform-tools" + - echo y | ~/android_sdk/cmdline-tools/latest/bin/sdkmanager --install "$ANDROID_PLATFORM" + - echo y | ~/android_sdk/cmdline-tools/latest/bin/sdkmanager --install "$ANDROID_BUILD_TOOLS" + - echo y | ~/android_sdk/cmdline-tools/latest/bin/sdkmanager --install "$ANDROID_EMULATOR_IMAGE" + - yes | ~/android_sdk/cmdline-tools/latest/bin/sdkmanager --licenses || true + - echo "no" | ~/android_sdk/cmdline-tools/latest/bin/avdmanager --verbose create avd --force --name "$EMULATOR_NAME" --package "$ANDROID_EMULATOR_IMAGE" + run-instrumented-integration: + - $ANDROID_HOME/emulator/emulator -avd "$EMULATOR_NAME" -grpc-use-jwt -no-snapstorage -no-audio -no-window -no-boot-anim -verbose -qemu -machine virt & + - GRADLE_OPTS="-Xmx3072m" ./gradlew :instrumented:integration:assembleDebug :instrumented:integration:assembleDebugAndroidTest --stacktrace --no-daemon + - ./android-wait-for-emulator.sh + - set +e + - $ANDROID_HOME/platform-tools/adb install -t -d -g -r instrumented/integration/build/outputs/apk/androidTest/debug/integration-debug-androidTest.apk + - $ANDROID_HOME/platform-tools/adb install -t -d -g -r instrumented/integration/build/outputs/apk/debug/integration-debug.apk + - $ANDROID_HOME/platform-tools/adb shell am instrument -w com.datadog.android.sdk.integration.test/androidx.test.runner.AndroidJUnitRunner + - $ANDROID_HOME/platform-tools/adb emu kill + # CI IMAGE ci-image: @@ -115,7 +148,6 @@ test:tools: - export DD_AGENT_HOST="$BUILDENV_HOST_IP" - GRADLE_OPTS="-Xmx3072m" ./gradlew :unitTestTools --stacktrace --no-daemon --build-cache --gradle-user-home cache/ - test:kover: tags: [ "arch:amd64" ] image: $CI_IMAGE_DOCKER @@ -211,6 +243,50 @@ test-pyramid:single-fit-trace: reports: junit: "**/build/test-results/testReleaseUnitTest/*.xml" +# RUN INSTRUMENTED TESTS ON MIN API (21), LATEST API (34) and MEDIAN API (28) + +test-pyramid:instrumented-legacy-min-api: + tags: [ "macos:sonoma" ] + image: $CI_IMAGE_DOCKER + stage: test-pyramid + timeout: 1h + variables: + ANDROID_API: "21" + ANDROID_EMULATOR_IMAGE: "system-images;android-$ANDROID_API;google_apis;${ANDROID_ARCH}" + ANDROID_PLATFORM: "platforms;android-$ANDROID_API" + ANDROID_BUILD_TOOLS: "build-tools;$ANDROID_API.0.0" + script: + - !reference [.snippets, install-android-sdk] + - !reference [.snippets, run-instrumented-integration] + +test-pyramid:instrumented-legacy-latest-api: + tags: [ "macos:sonoma" ] + image: $CI_IMAGE_DOCKER + stage: test-pyramid + timeout: 1h + variables: + ANDROID_API: "34" + ANDROID_EMULATOR_IMAGE: "system-images;android-$ANDROID_API;google_apis;${ANDROID_ARCH}" + ANDROID_PLATFORM: "platforms;android-$ANDROID_API" + ANDROID_BUILD_TOOLS: "build-tools;$ANDROID_API.0.0" + script: + - !reference [.snippets, install-android-sdk] + - !reference [.snippets, run-instrumented-integration] + +test-pyramid:instrumented-legacy-median-api: + tags: [ "macos:sonoma" ] + image: $CI_IMAGE_DOCKER + stage: test-pyramid + timeout: 1h + variables: + ANDROID_API: "28" + ANDROID_EMULATOR_IMAGE: "system-images;android-$ANDROID_API;google_apis;${ANDROID_ARCH}" + ANDROID_PLATFORM: "platforms;android-$ANDROID_API" + ANDROID_BUILD_TOOLS: "build-tools;$ANDROID_API.0.0" + script: + - !reference [.snippets, install-android-sdk] + - !reference [.snippets, run-instrumented-integration] + test-pyramid:publish-e2e-synthetics: tags: [ "arch:amd64" ] image: $CI_IMAGE_DOCKER diff --git a/android-wait-for-emulator.sh b/android-wait-for-emulator.sh new file mode 100755 index 0000000000..e915002928 --- /dev/null +++ b/android-wait-for-emulator.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Originally written by Ralf Kistner , but placed in the public domain + +set +e + +bootanim="" +failcounter=0 +timeout_in_sec=360 + +until [[ "$bootanim" =~ "stopped" ]]; do + bootanim=`adb -e shell getprop init.svc.bootanim 2>&1 &` + if [[ "$bootanim" =~ "device not found" || "$bootanim" =~ "device offline" + || "$bootanim" =~ "running" ]]; then + let "failcounter += 1" + echo "Waiting for emulator to start" + if [[ $failcounter -gt timeout_in_sec ]]; then + echo "Timeout ($timeout_in_sec seconds) reached; failed to start emulator" + exit 1 + fi + fi + sleep 1 +done + +echo "Emulator is ready" \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 685bd5c559..76991d4eb0 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -73,6 +73,9 @@ gradlePlugin { } } +java.targetCompatibility = JavaVersion.VERSION_17 +java.sourceCompatibility = JavaVersion.VERSION_17 + tasks.withType().configureEach { compilerOptions { jvmTarget.set(JvmTarget.JVM_17) diff --git a/gradle.properties b/gradle.properties index 55a4d553ce..3f45eff093 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,4 +5,7 @@ # org.gradle.jvmargs=-Xmx4096m android.useAndroidX=true + +# Allows Kotlin with target JVM compat 17 to be built on JDK 21 +kotlin.jvm.target.validation.mode = IGNORE # Leave the next line blank for CI