From d4e512aabec4dbc8279e9260f0ee9bcbf946a2ef Mon Sep 17 00:00:00 2001 From: iusmac Date: Sat, 31 Aug 2024 11:12:40 +0200 Subject: [PATCH] ci: generate code coverage summary using `Kover` Signed-off-by: iusmac --- .github/actions/android-build/action.yml | 24 +++++++++++++++- .github/scripts/post-build-with-gradle.sh | 1 + build.gradle | 34 +++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/.github/actions/android-build/action.yml b/.github/actions/android-build/action.yml index a4212a4..5d9f75c 100644 --- a/.github/actions/android-build/action.yml +++ b/.github/actions/android-build/action.yml @@ -42,7 +42,29 @@ runs: ${{ inputs.exclude-ci-info == 'false' && format('CI (N. {0} ID {1} from: {2})', github.run_number, github.run_id, github.head_ref || github.ref_name) || '' }} RELEASE_DEBUG_OPT: ${{ inputs.release-debug-opt }} - run: ./gradlew --parallel ${{ inputs.check-build == 'true' && 'build' || 'assemble' }} + run: | + ./gradlew --parallel \ + ${{ inputs.check-build == 'true' && 'build koverHtmlReportDebug koverXmlReportDebug' || 'assemble' }} + - name: Generate code coverage summary + if: inputs.check-build == 'true' + id: coverage + uses: PavanMudigonda/jacoco-reporter@v5.0 + with: + coverage_results_path: build/reports/kover/reportDebug.xml + github_token: ${{ github.token }} + skip_check_run: true + minimum_coverage: 80 + fail_below_threshold: false + - name: Add coverage report to workflow run summary + shell: bash + run: | + echo "## Coverage (Kover)" >> $GITHUB_STEP_SUMMARY + echo "| Outcome | Value |" >> $GITHUB_STEP_SUMMARY + echo "| --- | --- |" >> $GITHUB_STEP_SUMMARY + echo "| Code Coverage % | ${{ steps.coverage.outputs.coverage_percentage }} |" >> $GITHUB_STEP_SUMMARY + echo "| :heavy_check_mark: Number of Lines Covered | ${{ steps.coverage.outputs.covered_lines }} |" >> $GITHUB_STEP_SUMMARY + echo "| :x: Number of Lines Missed | ${{ steps.coverage.outputs.missed_lines }} |" >> $GITHUB_STEP_SUMMARY + echo "| Total Number of Lines | ${{ steps.coverage.outputs.total_lines }} |" >> $GITHUB_STEP_SUMMARY - name: Post Build with Gradle shell: bash run: ./.github/scripts/post-build-with-gradle.sh diff --git a/.github/scripts/post-build-with-gradle.sh b/.github/scripts/post-build-with-gradle.sh index 436e034..10a3b79 100755 --- a/.github/scripts/post-build-with-gradle.sh +++ b/.github/scripts/post-build-with-gradle.sh @@ -15,6 +15,7 @@ mkdir -vp "$artifacts_dir" # Move artifacts into a dedicated directory mv -v build/outputs/apk/{debug,release}/*.apk "$artifacts_dir" +mv -v build/reports/kover/htmlDebug/ "$artifacts_dir/koverDebug" || true mv -v build/reports/lint-results-debug.html "$artifacts_dir" || true # NOTE: MD5/SHA256sum commands output as ' ', so we should diff --git a/build.gradle b/build.gradle index 4fabacf..9d5e75f 100644 --- a/build.gradle +++ b/build.gradle @@ -64,6 +64,8 @@ plugins { id 'org.jetbrains.kotlin.android' version '1.9.22' apply false // https://mvnrepository.com/artifact/net.ltgt.errorprone/net.ltgt.errorprone.gradle.plugin id 'net.ltgt.errorprone' version '4.0.1' apply false + // https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kover-gradle-plugin + id 'org.jetbrains.kotlinx.kover' version '0.8.3' apply false } allprojects { @@ -101,6 +103,7 @@ apply plugin: 'com.android.application' apply plugin: 'org.jetbrains.kotlin.android' apply plugin: 'kotlin-kapt' apply plugin: 'net.ltgt.errorprone' +apply plugin: 'org.jetbrains.kotlinx.kover' final def versionNameCommon = [file('version.txt').text.trim()] if (System.getenv('EXTRA_VERSION_BUILD_INFO') == null) { @@ -233,6 +236,37 @@ kapt { correctErrorTypes true } +kover { + reports { + filters { + excludes { + // excludes class by fully-qualified JVM class name, wildcards + // '*' and '?' are available + classes( + '*BuildConfig', + // '*\$Factory', + '*.Hilt_*', + '*_ComponentTreeDeps', + '*_HiltComponents*', + '*_Impl', + '*_Impl\$*', + ) + // excludes all classes located in specified package and it + // subpackages, wildcards '*' and '?' are available + packages( + 'com.github.iusmac.sevensim.inject', + 'hilt_aggregated_deps', + 'dagger.hilt.internal.*', + ) + // excludes all classes and functions, annotated by specified + // annotations, wildcards '*' and '?' are available + annotatedBy('*Generated*') + annotatedBy('*AssistedFactory') + } + } + } +} + /** * Describe the tag relative to a commit-ish using "git describe". *