Skip to content

Commit

Permalink
chore(codecov) : add codecov, jacoco (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
JagadeeshKaricherla-branch authored Oct 10, 2023
1 parent ddbcef2 commit 452a473
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/unit-and-instrumented-tests-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
with:
name: unit-test-api-level-$API_MIN
path: ./Branch-SDK/build/

instrumented-test-api-level-min:
name: instrumented-test-api-level-$API_MIN
runs-on: macos-latest
Expand Down Expand Up @@ -66,6 +67,44 @@ jobs:
with:
name: instrumented-test-api-level-$API_MIN
path: ./Branch-SDK/build/

jacoco-test-coverage-api-level-min:
name: jacoco-test-coverage-api-level-$API_MIN
if: ${{ always() && contains(join(needs.*.result, ','), 'success') }}
needs: [unit-test-api-level-min, instrumented-test-api-level-min]
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# create an emulator with google apis, runs on java 8
- name: Create Android emulator
run: |
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --licenses
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-"$API_MIN";google_apis;x86_64"
echo "no" | $ANDROID_HOME/tools/bin/avdmanager --verbose create avd --force --name test --package "system-images;android-"$API_MIN";google_apis;x86_64"
# boots and waits for the emulator to be ready
- name: Launch Emulator
run: |
echo "Starting emulator and waiting for boot to complete."
nohup $ANDROID_HOME/tools/emulator -avd test -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 2>&1 &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do echo "waiting..."; sleep 1; done; input keyevent 82'
echo "Emulator has finished booting"
# repo's gradle is configured to run on java 17
- name: Setup java 17 for gradle
uses: actions/setup-java@v3
with:
distribution: ${{ env.JAVA_DISTRIBUTION }}
java-version: ${{ env.JAVA_VERSION }}
- name: Run Coverage
run: |
./gradlew :Branch-SDK:jacocoTestReport --info
- name: Upload Coverage Test Report
if: success()
uses: codecov/codecov-action@v3
with:
file: ./Branch-SDK/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml
fail_ci_if_error: true

unit-test-api-level-current:
name: unit-test-api-level-$API_CURRENT
runs-on: macos-latest
Expand Down
30 changes: 30 additions & 0 deletions Branch-SDK/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ plugins {
`maven-publish`
signing
id("org.gradle.test-retry") version "1.5.3"
id("jacoco")
}
val coroutinesVersion = "1.6.4"
jacoco {
toolVersion = "0.8.10"
}

dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to "*.jar")))
Expand Down Expand Up @@ -92,6 +96,7 @@ android {

debug {
enableUnitTestCoverage = true
enableAndroidTestCoverage = true
buildConfigField("long", "VERSION_CODE", VERSION_CODE)
buildConfigField("String", "VERSION_NAME", VERSION_NAME.wrapInQuotes())
}
Expand Down Expand Up @@ -274,5 +279,30 @@ tasks {
retry {
maxRetries.set(3)
}
configure<JacocoTaskExtension> {
isIncludeNoLocationClasses = true
excludes = listOf("jdk.internal.*")
}
}
}

tasks.create<JacocoReport>("jacocoTestReport") {
group = "Reporting"
description = "Generate Jacoco code coverage reports after running tests."
dependsOn("testDebugUnitTest","createDebugCoverageReport")
reports {
xml.required.set(true)
html.required.set(true)
}
sourceDirectories.setFrom("${project.projectDir}/src/main/java")
classDirectories.setFrom("${project.buildDir}/intermediates/javac/debug/classes")
executionData.setFrom(
fileTree(project.buildDir) {
include(
"jacoco/testDebugUnitTest.exec",
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
"outputs/code_coverage/debugAndroidTest/connected/**/*.ec",
)
}
)
}

0 comments on commit 452a473

Please sign in to comment.