Skip to content

Commit

Permalink
Codecov reports for Android modules (#2868)
Browse files Browse the repository at this point in the history
* Add coverage report for unit test on sentry-android-core

* Try running coverage report for android (FOR TESTING PURPOSES ONLY)

* Format code

* Retrigger checks

* Try clean firsT

* Use makefile

* Try running testDebugUnitTest first

* Run test only

* list tasks

* disable cache

* Try with release unit test

* Try with release build

* Specify files to upload for codecov

* fix typo

* Add archiving

* Without upload

* Try matching all android build dirs during codecov upload

* Enable unit test coverage for android modules

* Create task

* Exclude sentry-android-integration-tests

* Format code

* Try whole process

* Try without specifying files

* No archive

* Rename reports file

* Add coverage task in makefile

* Reset workflow file

* Remove coverage for debug

* Test

* Test

* Fix build error

* Test without archiving

* Test with array of android module strings

* Try with different classes folders

* Fix classes dir name

* Format code

* Include sentry-compose

* Adjust sentry-compose source dir

* Fix subproject name reference

* Revert some changes

* Revert some changes

* Cleanup

* Use gradle plugin

* Apply binary plugin

* Improve copy and reduce code duplication

* (don't merge): debugging Kover

* (don't merge): debugging Kover

* (don't merge): remove archiving for now

* (don't merge): specify file path for codecov

* (don't merge): specify file path for codecov

* Revert build.yml

* Apply jacoco manually for sentry-compose

* Remove renaming of report

* Fix 'this' receiver

* (don't merge): test kover

* (don't merge): use release variant)

* (don't merge): run test before kover

* (don't merge): change report file name

* Format code

* (don't merge): try specifying the file

* (don't merge): try renaming the kover report

* Format code

* Add Kover for KMP modules

* Formatting

* Remove Kover configuration in sentry-compose build.gradle.kts

---------

Co-authored-by: Sentry Github Bot <bot+github-bot@sentry.io>
  • Loading branch information
buenaflor and getsentry-bot authored Aug 10, 2023
1 parent 9f752eb commit d55d97a
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 51 deletions.
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: all clean compile javadocs dryRelease update stop checkFormat format api assembleBenchmarkTestRelease assembleUiTestRelease
.PHONY: all clean compile javadocs dryRelease update stop checkFormat format api assembleBenchmarkTestRelease assembleUiTestRelease createCoverageReports

all: stop clean javadocs compile
all: stop clean javadocs compile createCoverageReports
assembleBenchmarks: stop clean assembleBenchmarkTestRelease
assembleUiTests: stop clean assembleUiTestRelease

Expand Down Expand Up @@ -50,3 +50,10 @@ assembleBenchmarkTestRelease:
assembleUiTestRelease:
./gradlew :sentry-android-integration-tests:sentry-uitest-android:assembleRelease
./gradlew :sentry-android-integration-tests:sentry-uitest-android:assembleAndroidTest -DtestBuildType=release

# Create coverage reports
# - Jacoco for Java & Android modules
# - Kover for KMP modules e.g sentry-compose
createCoverageReports:
./gradlew jacocoTestReport
./gradlew koverXmlReportRelease
41 changes: 41 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.vanniktech.maven.publish.MavenPublishPlugin
import com.vanniktech.maven.publish.MavenPublishPluginExtension
import groovy.util.Node
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import kotlinx.kover.gradle.plugin.dsl.KoverReportExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

Expand All @@ -14,6 +15,8 @@ plugins {
id(Config.QualityPlugins.detekt) version Config.QualityPlugins.detektVersion
`maven-publish`
id(Config.QualityPlugins.binaryCompatibilityValidator) version Config.QualityPlugins.binaryCompatibilityValidatorVersion
id(Config.QualityPlugins.jacocoAndroid) version Config.QualityPlugins.jacocoAndroidVersion apply false
id(Config.QualityPlugins.kover) version Config.QualityPlugins.koverVersion apply false
}

buildscript {
Expand Down Expand Up @@ -97,6 +100,44 @@ allprojects {
}

subprojects {
val jacocoAndroidModules = listOf(
"sentry-android-core",
"sentry-android-fragment",
"sentry-android-navigation",
"sentry-android-ndk",
"sentry-android-okhttp",
"sentry-android-sqlite",
"sentry-android-timber"
)
if (jacocoAndroidModules.contains(name)) {
afterEvaluate {
jacoco {
toolVersion = "0.8.10"
}

tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
}
}
}

val koverKmpModules = listOf("sentry-compose")
if (koverKmpModules.contains(name)) {
afterEvaluate {
configure<KoverReportExtension> {
androidReports("release") {
xml {
// Change the report file name so the Codecov Github action can find it
setReportFile(file("$buildDir/reports/kover/report.xml"))
}
}
}
}
}

plugins.withId(Config.QualityPlugins.detektPlugin) {
configure<DetektExtension> {
buildUponDefaultConfig = true
Expand Down
5 changes: 5 additions & 0 deletions buildSrc/src/main/java/Config.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import java.math.BigDecimal

object Config {
Expand Down Expand Up @@ -205,6 +206,10 @@ object Config {
val binaryCompatibilityValidatorVersion = "0.13.0"
val binaryCompatibilityValidatorPlugin = "org.jetbrains.kotlinx:binary-compatibility-validator:$binaryCompatibilityValidatorVersion"
val binaryCompatibilityValidator = "org.jetbrains.kotlinx.binary-compatibility-validator"
val jacocoAndroid = "com.mxalbert.gradle.jacoco-android"
val jacocoAndroidVersion = "0.2.0"
val kover = "org.jetbrains.kotlinx.kover"
val koverVersion = "0.7.3"
}

object Sentry {
Expand Down
7 changes: 1 addition & 6 deletions sentry-android-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id("com.android.library")
kotlin("android")
jacoco
id(Config.QualityPlugins.jacocoAndroid)
id(Config.QualityPlugins.errorProne)
id(Config.QualityPlugins.gradleVersions)
}
Expand Down Expand Up @@ -64,12 +65,6 @@ android {
}
}

tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = false
}
}

tasks.withType<JavaCompile>().configureEach {
options.errorprone {
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.ERROR)
Expand Down
7 changes: 1 addition & 6 deletions sentry-android-fragment/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id("com.android.library")
kotlin("android")
jacoco
id(Config.QualityPlugins.jacocoAndroid)
id(Config.QualityPlugins.gradleVersions)
id(Config.QualityPlugins.detektPlugin)
}
Expand Down Expand Up @@ -54,12 +55,6 @@ android {
}
}

tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = false
}
}

kotlin {
explicitApi()
}
Expand Down
7 changes: 1 addition & 6 deletions sentry-android-navigation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id("com.android.library")
kotlin("android")
jacoco
id(Config.QualityPlugins.jacocoAndroid)
id(Config.QualityPlugins.gradleVersions)
id(Config.QualityPlugins.detektPlugin)
}
Expand Down Expand Up @@ -55,12 +56,6 @@ android {
}
}

tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = false
}
}

kotlin {
explicitApi()
}
Expand Down
7 changes: 1 addition & 6 deletions sentry-android-ndk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id("com.android.library")
kotlin("android")
jacoco
id(Config.QualityPlugins.jacocoAndroid)
id(Config.NativePlugins.nativeBundleExport)
id(Config.QualityPlugins.gradleVersions)
}
Expand Down Expand Up @@ -96,12 +97,6 @@ android {
}
}

tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = false
}
}

dependencies {
api(projects.sentry)
api(projects.sentryAndroidCore)
Expand Down
7 changes: 1 addition & 6 deletions sentry-android-okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id("com.android.library")
kotlin("android")
jacoco
id(Config.QualityPlugins.jacocoAndroid)
id(Config.QualityPlugins.gradleVersions)
id(Config.QualityPlugins.detektPlugin)
}
Expand Down Expand Up @@ -56,12 +57,6 @@ android {
}
}

tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = false
}
}

kotlin {
explicitApi()
}
Expand Down
7 changes: 1 addition & 6 deletions sentry-android-sqlite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id("com.android.library")
kotlin("android")
jacoco
id(Config.QualityPlugins.jacocoAndroid)
id(Config.QualityPlugins.gradleVersions)
id(Config.QualityPlugins.detektPlugin)
}
Expand Down Expand Up @@ -56,12 +57,6 @@ android {
}
}

tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = false
}
}

kotlin {
explicitApi()
}
Expand Down
7 changes: 1 addition & 6 deletions sentry-android-timber/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id("com.android.library")
kotlin("android")
jacoco
id(Config.QualityPlugins.jacocoAndroid)
id(Config.QualityPlugins.gradleVersions)
id(Config.QualityPlugins.detektPlugin)
}
Expand Down Expand Up @@ -59,12 +60,6 @@ android {
}
}

tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = false
}
}

kotlin {
explicitApi()
}
Expand Down
8 changes: 1 addition & 7 deletions sentry-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
kotlin("multiplatform")
id("com.android.library")
id("org.jetbrains.compose")
jacoco
id(Config.QualityPlugins.kover)
id(Config.QualityPlugins.gradleVersions)
id(Config.QualityPlugins.detektPlugin)
id(Config.BuildPlugins.dokkaPluginAlias)
Expand Down Expand Up @@ -113,12 +113,6 @@ android {
}
}

tasks.withType<Test> {
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = false
}
}

tasks.withType<Detekt> {
// Target version of the generated JVM bytecode. It is used for type resolution.
jvmTarget = JavaVersion.VERSION_1_8.toString()
Expand Down

0 comments on commit d55d97a

Please sign in to comment.