Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynafs authored and kibettheophilus committed Jun 14, 2024
1 parent 5eb422f commit b6bc0fb
Show file tree
Hide file tree
Showing 16 changed files with 236 additions and 74 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
env:
APP_SIGN_KEYSTORE_PATH: /tmp/keystore
CACHE_BUNDLER: ~/.bundler
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

jobs:
build:
Expand Down Expand Up @@ -89,4 +90,14 @@ jobs:
options: '{ "conf": "debug" }'
skip-tracking: false
subdirectory: fastlane
bundle-install-path: CACHE_BUNDLER
bundle-install-path: CACHE_BUNDLER

- name: Upload App module test coverage report to Codecov
if: matrix.api-level == 30 # Only upload coverage on API level 30
working-directory: android
run: bash <(curl -s https://codecov.io/bash) -F app -f "**/build/reports/jacoco/"

- name: Upload DataSource module test coverage report to Codecov
if: matrix.api-level == 30 # Only upload coverage on API level 30
working-directory: android
run: bash <(curl -s https://codecov.io/bash) -F datasource -f "**/build/reports/jacoco/"
25 changes: 1 addition & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,4 @@ jobs:
options: '{ "conf": "release" }'
skip-tracking: false
subdirectory: fastlane
bundle-install-path: CACHE_BUNDLER

- name: Upload test coverage report to Codecov
if: matrix.api-level == 30
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Run tests with coverage
run: ./gradlew debugCoverage


- name: Upload test results
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: test-results
path: "build/reports/tests"

- name: Upload jacoco report
uses: actions/upload-artifact@v4
with:
name: jacoco-report
path: "build/reports/jacoco"
bundle-install-path: CACHE_BUNDLER
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
alias(libs.plugins.droidconke.android.hilt)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.droidconke.android.application.firebase)
alias(libs.plugins.droidconke.android.application.jacoco)
}

android {
Expand Down
8 changes: 8 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ gradlePlugin {
id = "droidconke.android.application"
implementationClass = "AndroidApplicationConventionPlugin"
}
register("androidApplicationJacoco") {
id = "droidconke.android.application.jacoco"
implementationClass = "AndroidApplicationJacocoConventionPlugin"
}
register("androidLibraryJacoco") {
id = "droidconke.android.library.jacoco"
implementationClass = "AndroidLibraryJacocoConventionPlugin"
}
register("multiplatform") {
id = "droidconke.multiplatform"
implementationClass = "MultiplaftormConventionPlugin"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import com.android.build.api.variant.ApplicationAndroidComponentsExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import com.android254.configureJacoco
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType

class AndroidApplicationJacocoConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("jacoco")
val androidExtension = extensions.getByType<BaseAppModuleExtension>()

androidExtension.buildTypes.configureEach {
enableAndroidTestCoverage = true
enableUnitTestCoverage = true
}

configureJacoco(extensions.getByType<ApplicationAndroidComponentsExtension>())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import com.android.build.api.dsl.LibraryExtension
import com.android.build.api.variant.LibraryAndroidComponentsExtension
import com.android254.configureJacoco
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getByType

class AndroidLibraryJacocoConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
pluginManager.apply("jacoco")
val androidExtension = extensions.getByType<LibraryExtension>()

androidExtension.buildTypes.configureEach {
enableAndroidTestCoverage = true
enableUnitTestCoverage = true
}

configureJacoco(extensions.getByType<LibraryAndroidComponentsExtension>())
}
}
}
103 changes: 103 additions & 0 deletions build-logic/convention/src/main/kotlin/com/android254/Jacoco.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.android254

import com.android.build.api.artifact.ScopedArtifact
import com.android.build.api.variant.AndroidComponentsExtension
import com.android.build.api.variant.ScopedArtifacts
import org.gradle.api.Project
import org.gradle.api.file.Directory
import org.gradle.api.file.RegularFile
import org.gradle.api.provider.ListProperty
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension
import org.gradle.testing.jacoco.tasks.JacocoReport
import java.util.Locale

private val coverageExclusions = listOf(
// Android
"**/R.class",
"**/R\$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*_Hilt*.class",
"**/Hilt_*.class",
)

private fun String.capitalize() = replaceFirstChar {
if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString()
}

/**
* Creates a new task that generates a combined coverage report with data from local and
* instrumented tests.
*
* `create{variant}CombinedCoverageReport`
*
* Note that coverage data must exist before running the task. This allows us to run device
* tests on CI using a different Github Action or an external device farm.
*/
internal fun Project.configureJacoco(
androidComponentsExtension: AndroidComponentsExtension<*, *, *>,
) {
configure<JacocoPluginExtension> {
toolVersion = libs.findVersion("jacoco").get().toString()
}

androidComponentsExtension.onVariants { variant ->
val myObjFactory = project.objects
val buildDir = layout.buildDirectory.get().asFile
val allJars: ListProperty<RegularFile> = myObjFactory.listProperty(RegularFile::class.java)
val allDirectories: ListProperty<Directory> = myObjFactory.listProperty(Directory::class.java)
val reportTask =
tasks.register("create${variant.name.capitalize()}CombinedCoverageReport", JacocoReport::class) {

classDirectories.setFrom(
allJars,
allDirectories.map { dirs ->
dirs.map { dir ->
myObjFactory.fileTree().setDir(dir).exclude(coverageExclusions)
}
}
)
reports {
xml.required.set(true)
html.required.set(true)
}

// TODO: This is missing files in src/debug/, src/prod, src/demo, src/demoDebug...
sourceDirectories.setFrom(files("$projectDir/src/main/java", "$projectDir/src/main/kotlin"))

executionData.setFrom(
project.fileTree("$buildDir/outputs/unit_test_code_coverage/${variant.name}UnitTest")
.matching { include("**/*.exec") },

project.fileTree("$buildDir/outputs/code_coverage/${variant.name}AndroidTest")
.matching { include("**/*.ec") }
)
}


variant.artifacts.forScope(ScopedArtifacts.Scope.PROJECT)
.use(reportTask)
.toGet(
ScopedArtifact.CLASSES,
{ _ -> allJars },
{ _ -> allDirectories },
)
}

tasks.withType<Test>().configureEach {
configure<JacocoTaskExtension> {
// Required for JaCoCo + Robolectric
// https://github.com/robolectric/robolectric/issues/2230
isIncludeNoLocationClasses = true

// Required for JDK 11 with the above
// https://github.com/gradle/gradle/issues/5184#issuecomment-391982009
excludes = listOf("jdk.internal.*")
}
}
}
14 changes: 0 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,4 @@ subprojects {
licenseHeaderFile(rootProject.file("spotless/copyright.kts"), "(^(?![\\/ ]\\*).*$)")
}
}

apply(plugin = "jacoco")

configure<JacocoPluginExtension> { toolVersion = "0.8.7" }

tasks.register<JacocoReport>("debugCoverage") {
group = "Reporting"
description = "Generate Jacoco coverage reports for the debug build."
reports {
xml.required.set(true)
html.required.set(true)
}
}

}
1 change: 1 addition & 0 deletions chai/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
plugins {
alias(libs.plugins.droidconke.android.library)
alias(libs.plugins.droidconke.android.library.compose)
alias(libs.plugins.droidconke.android.library.jacoco)
alias(libs.plugins.compose.compiler)
}

Expand Down
23 changes: 23 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
codecov:
notify:
wait_for_ci: true
max_report_age: off
require_ci_to_pass: true
comment:
behavior: default
layout: "reach, diff, flags, files"
show_carryforward_flags: false
coverage:
precision: 1
status:
changes: false
patch:
default:
target: 60.0
project:
default:
enabled: true
target: 25.0
flag_management:
default_rules:
carryforward: true
1 change: 1 addition & 0 deletions data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
alias(libs.plugins.droidconke.android.hilt)
alias(libs.plugins.droidconke.android.library.firebase)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.droidconke.android.library.jacoco)
}

android {
Expand Down
1 change: 1 addition & 0 deletions datasource/local/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
alias(libs.plugins.droidconke.android.room)
alias(libs.plugins.droidconke.android.hilt)
alias(libs.plugins.droidconke.android.library.firebase)
alias(libs.plugins.droidconke.android.library.jacoco)
}

android {
Expand Down
1 change: 1 addition & 0 deletions datasource/remote/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ plugins {
alias(libs.plugins.droidconke.android.hilt)
alias(libs.plugins.droidconke.android.library.firebase)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.droidconke.android.library.jacoco)
}

android {
Expand Down
1 change: 1 addition & 0 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
plugins {
alias(libs.plugins.droidconke.android.library)
alias(libs.plugins.droidconke.android.library.jacoco)
}

android {
Expand Down
Loading

0 comments on commit b6bc0fb

Please sign in to comment.