Skip to content

Commit

Permalink
Merge branch 'master' into ak/flag-for-submit-button
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya-07 committed Feb 6, 2023
2 parents ac5b643 + b6c7116 commit 5969983
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 59 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath(Plugins.androidGradlePlugin)
classpath(Plugins.benchmarkGradlePlugin)
classpath(Plugins.flankGradlePlugin)
classpath(Plugins.kotlinGradlePlugin)
classpath(Plugins.navSafeArgsGradlePlugin)
classpath(Plugins.rulerGradlePlugin)
Expand Down
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation("com.android.tools.build:gradle:7.1.1")

implementation("app.cash.licensee:licensee-gradle-plugin:1.3.0")
implementation("com.osacky.flank.gradle:fladle:0.17.4")

implementation("com.spotify.ruler:ruler-gradle-plugin:1.2.1")

Expand Down
67 changes: 67 additions & 0 deletions buildSrc/src/main/kotlin/FirebaseTestLabConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.android.build.api.dsl.LibraryExtension
import java.util.UUID
import org.gradle.api.Project
import org.gradle.kotlin.dsl.apply
import org.gradle.kotlin.dsl.configure

@Suppress("SdCardPath")
fun Project.configureFirebaseTestLab() {
apply(plugin = Plugins.BuildPlugins.fladle)
configure<com.osacky.flank.gradle.FlankGradleExtension> {
projectId.set("android-fhir-instrumeted-tests")
debugApk.set(
project.provider {
"$rootDir/demo/build/outputs/apk/androidTest/debug/demo-debug-androidTest.apk"
}
)
devices.set(
listOf(
mapOf(
"model" to "Nexus6P",
"version" to
"${this@configureFirebaseTestLab.extensions.getByType(LibraryExtension::class.java).defaultConfig.minSdk}",
"locale" to "en_US"
),
mapOf("model" to "Nexus6P", "version" to "27", "locale" to "en_US"),
mapOf(
"model" to "oriole",
"version" to
"${this@configureFirebaseTestLab.extensions.getByType(LibraryExtension::class.java).defaultConfig.targetSdk}",
"locale" to "en_US"
),
)
)
instrumentationApk.set(project.provider { "$buildDir/outputs/apk/androidTest/debug/*.apk" })
useOrchestrator.set(false)
flakyTestAttempts.set(3)
environmentVariables.set(
mapOf("coverage" to "true", "coverageFile" to "/sdcard/Download/coverage.ec")
)
directoriesToPull.set(listOf("/sdcard/Download"))
filesToDownload.set(listOf(".*/sdcard/Download/.*.ec"))
resultsBucket.set("android-fhir-build-artifacts")
resultsDir.set(
if (project.providers.environmentVariable("KOKORO_BUILD_ARTIFACTS_SUBDIR").isPresent) {
"${System.getenv("KOKORO_BUILD_ARTIFACTS_SUBDIR")}/firebase/${project.name}"
} else {
"${project.name}-${UUID.randomUUID()}"
}
)
}
}
17 changes: 15 additions & 2 deletions buildSrc/src/main/kotlin/JacocoConfig.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Google LLC
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,7 +57,18 @@ fun Project.createJacocoTestReportTask() {
html.required.set(true)
}
sourceDirectories.setFrom("$projectDir/src/main/java")
classDirectories.setFrom(fileTree("$buildDir/tmp/kotlin-classes/debug"))
classDirectories.setFrom(
fileTree("$buildDir/tmp/kotlin-classes/debug")
.exclude(
"**/R.class",
"**/R$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*Test*.*",
"android/**/*.*"
)
)

executionData.setFrom(
fileTree(buildDir) {
include(
Expand All @@ -66,6 +77,8 @@ fun Project.createJacocoTestReportTask() {
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
// Instrumentation coverage report location
"outputs/code_coverage/debugAndroidTest/connected/**/*.ec",
// Instrumentation coverage report location from Firebase Test Lab
"fladle/results/**/*.ec",
)
)
}
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Plugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object Plugins {
const val kotlinAndroid = "kotlin-android"
const val kotlinKapt = "kotlin-kapt"
const val mavenPublish = "maven-publish"
const val fladle = "com.osacky.fladle"
const val navSafeArgs = "androidx.navigation.safeargs.kotlin"
const val ruler = "com.spotify.ruler"
const val spotless = "com.diffplug.spotless"
Expand All @@ -40,6 +41,7 @@ object Plugins {
const val navSafeArgsGradlePlugin =
"androidx.navigation:navigation-safe-args-gradle-plugin:${Dependencies.Versions.Androidx.navigation}"
const val rulerGradlePlugin = "com.spotify.ruler:ruler-gradle-plugin:1.2.1"
const val flankGradlePlugin = "com.osacky.flank.gradle:fladle:0.17.4"

object Versions {
const val androidGradlePlugin = "7.2.1"
Expand Down
2 changes: 2 additions & 0 deletions datacapture/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ android {
testOptions { animationsDisabled = true }
}

afterEvaluate { configureFirebaseTestLab() }

configurations { all { exclude(module = "xpp3") } }

dependencies {
Expand Down
2 changes: 2 additions & 0 deletions engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ android {
configureJacocoTestOptions()
}

afterEvaluate { configureFirebaseTestLab() }

configurations {
all {
exclude(module = "json")
Expand Down
66 changes: 9 additions & 57 deletions kokoro/gcp_ubuntu/kokoro_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,67 +87,19 @@ function build_only() {
}

# Runs instrumentation tests using Firebase Test Lab, and retrieves the code
# coverage reports. First, we have to create the APKs to upload to Firebase.
# There are four APKs that we use: one for each of the libraries we want to test,
# and one for the demo app.
#
# 9 tests run in total: for each library, we run against 3 different API levels.
# The tests for each library run in parallel and as background processes, but,
# we wait for Firebase to finish execution of all the tests before pulling the
# code coverage results from the GCS bucket.
#
# See: https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run
# for documentation on the gcloud command used in this function
# See: https://cloud.google.com/storage/docs/gsutil/commands/cp
# for documentation on the gsutil command used in this function
# coverage reports.
function device_tests() {
./gradlew packageDebugAndroidTest --scan --stacktrace
local lib_names=("datacapture" "engine")
firebase_pids=()
for lib_name in "${lib_names[@]}"; do
gcloud firebase test android run --type instrumentation \
--app demo/build/outputs/apk/androidTest/debug/demo-debug-androidTest.apk \
--test $lib_name/build/outputs/apk/androidTest/debug/$lib_name-debug-androidTest.apk \
--timeout 30m \
--device model=Nexus6P,version=24,locale=en_US \
--device model=Nexus6P,version=27,locale=en_US \
--device model=Pixel2,version=30,locale=en_US \
--environment-variables coverage=true,coverageFile="/sdcard/Download/coverage.ec" \
--directories-to-pull /sdcard/Download \
--results-bucket=$GCS_BUCKET \
--results-dir=$KOKORO_BUILD_ARTIFACTS_SUBDIR/firebase/$lib_name \
--project=android-fhir-instrumeted-tests \
--num-flaky-test-attempts 3 \
--no-use-orchestrator &
firebase_pids+=("$!")
done

local lib_names_min_sdk_26=("workflow")
for lib_name in "${lib_names_min_sdk_26[@]}"; do
gcloud firebase test android run --type instrumentation \
--app demo/build/outputs/apk/androidTest/debug/demo-debug-androidTest.apk \
--test $lib_name/build/outputs/apk/androidTest/debug/$lib_name-debug-androidTest.apk \
--timeout 30m \
--device model=Nexus6P,version=27,locale=en_US \
--device model=Pixel2,version=30,locale=en_US \
--environment-variables coverage=true,coverageFile="/sdcard/Download/coverage.ec" \
--directories-to-pull /sdcard/Download \
--results-bucket=$GCS_BUCKET \
--results-dir=$KOKORO_BUILD_ARTIFACTS_SUBDIR/firebase/$lib_name \
--project=android-fhir-instrumeted-tests \
--no-use-orchestrator &
local lib_names=("datacapture" "engine" "workflow")
firebase_pids=()
for lib_name in "${lib_names[@]}"; do
./gradlew :$lib_name:runFlank --scan --stacktrace &
firebase_pids+=("$!")
done

for firebase_pid in ${firebase_pids[*]}; do
wait $firebase_pid
done
done

mkdir -p {datacapture,engine,workflow}/build/outputs/code_coverage/debugAndroidTest/connected/firebase
for lib_name in "${lib_names[@]}"; do
gsutil -m cp -R gs:https://$GCS_BUCKET/$KOKORO_BUILD_ARTIFACTS_SUBDIR/firebase/$lib_name/Pixel2-30-en_US-portrait/**/coverage.ec \
$lib_name/build/outputs/code_coverage/debugAndroidTest/connected/firebase
done
for firebase_pid in ${firebase_pids[*]}; do
wait $firebase_pid
done
}

# Generates JaCoCo reports and uploads to Codecov: https://about.codecov.io/
Expand Down
2 changes: 2 additions & 0 deletions workflow/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ android {
configureJacocoTestOptions()
}

afterEvaluate { configureFirebaseTestLab() }

configurations {
all {
removeIncompatibleDependencies()
Expand Down

0 comments on commit 5969983

Please sign in to comment.