From 84d10d763436bb407109004cdb6bf0b447147f1c Mon Sep 17 00:00:00 2001 From: Brian Yencho Date: Mon, 16 Oct 2023 10:12:39 -0500 Subject: [PATCH] BIT-755: Add Kover and Danger for code coverage (#103) --- .github/workflows/run-check.yml | 14 +++++- Dangerfile | 1 + Gemfile | 6 +++ Gemfile.lock | 80 +++++++++++++++++++++++++++++++++ README.md | 19 ++++++++ app/build.gradle.kts | 38 ++++++++++++++++ build.gradle.kts | 1 + gradle/libs.versions.toml | 2 + 8 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 Dangerfile create mode 100644 Gemfile create mode 100644 Gemfile.lock diff --git a/.github/workflows/run-check.yml b/.github/workflows/run-check.yml index cfa6a689a..4fa023981 100644 --- a/.github/workflows/run-check.yml +++ b/.github/workflows/run-check.yml @@ -7,6 +7,7 @@ on: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} JAVA_VERSION: 17 + RUBY_VERSION: 3.2.2 jobs: test: @@ -21,6 +22,12 @@ jobs: # https://github.community/t/push-from-action-even-with-pat-does-not-trigger-action/17622 persist-credentials: false + - name: Configure Ruby + uses: ruby/setup-ruby@52b8784594ec115fd17094752708121dc5dabb47 # v1.154.0 + with: + bundler-cache: true + ruby-version: ${{ env.RUBY_VERSION }} + - name: Configure JDK uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 with: @@ -30,4 +37,9 @@ jobs: - name: Build and Run Check # Run checks while excluding release-build tests, which are not configured to work properly # with the Compose testing library. - run: ./gradlew check -x testRelease + run: ./gradlew check -x testRelease koverXmlReportDebug + + - name: Danger + env: + DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: bundle exec danger diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 000000000..188a5eec6 --- /dev/null +++ b/Dangerfile @@ -0,0 +1 @@ +shroud.reportKover 'App', 'app/build/reports/kover/reportDebug.xml', 80, 80, false diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..7750df710 --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +ruby '3.2.2' + +gem 'danger' +gem 'danger-shroud' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..91edb95cb --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,80 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.8.5) + public_suffix (>= 2.0.2, < 6.0) + base64 (0.1.1) + claide (1.1.0) + claide-plugins (0.9.2) + cork + nap + open4 (~> 1.3) + colored2 (3.1.2) + cork (0.3.0) + colored2 (~> 3.1) + danger (9.3.2) + claide (~> 1.0) + claide-plugins (>= 0.9.2) + colored2 (~> 3.1) + cork (~> 0.1) + faraday (>= 0.9.0, < 3.0) + faraday-http-cache (~> 2.0) + git (~> 1.13) + kramdown (~> 2.3) + kramdown-parser-gfm (~> 1.0) + no_proxy_fix + octokit (~> 6.0) + terminal-table (>= 1, < 4) + danger-plugin-api (1.0.0) + danger (> 2.0) + danger-shroud (0.0.6) + danger-plugin-api (~> 1.0) + nokogiri + faraday (2.7.11) + base64 + faraday-net_http (>= 2.0, < 3.1) + ruby2_keywords (>= 0.0.4) + faraday-http-cache (2.5.0) + faraday (>= 0.8) + faraday-net_http (3.0.2) + git (1.18.0) + addressable (~> 2.8) + rchardet (~> 1.8) + kramdown (2.4.0) + rexml + kramdown-parser-gfm (1.1.0) + kramdown (~> 2.0) + mini_portile2 (2.8.4) + nap (1.1.0) + no_proxy_fix (0.1.2) + nokogiri (1.15.4) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) + octokit (6.1.1) + faraday (>= 1, < 3) + sawyer (~> 0.9) + open4 (1.3.4) + public_suffix (5.0.3) + racc (1.7.1) + rchardet (1.8.0) + rexml (3.2.6) + ruby2_keywords (0.0.5) + sawyer (0.9.2) + addressable (>= 2.3.5) + faraday (>= 0.17.3, < 3) + terminal-table (3.0.2) + unicode-display_width (>= 1.1.1, < 3) + unicode-display_width (2.5.0) + +PLATFORMS + ruby + +DEPENDENCIES + danger + danger-shroud + +RUBY VERSION + ruby 3.2.2p53 + +BUNDLED WITH + 2.1.4 diff --git a/README.md b/README.md index 93a9a0b1c..c4a41fb73 100644 --- a/README.md +++ b/README.md @@ -165,3 +165,22 @@ The following is a list of additional third-party dependencies used as part of t - https://github.com/cashapp/turbine - Purpose: A small testing library for kotlinx.coroutine's Flow. - License: Apache 2.0 + +### CI/CD Dependencies + +The following is a list of additional third-party dependencies used as part of the CI/CD workflows. These are not present in the final packaged application. + +- **Danger** + - https://github.com/danger/danger + - Purpose: Provides a system for enforcing common Pull Request rules. + - License: MIT + +- **Danger Shroud** + - https://github.com/livefront/danger-shroud + - Purpose: A Danger plugin for enforcing code coverage via Kover / Jacoco. + - License: Apache 2.0 + +- **Kover** + - https://github.com/Kotlin/kotlinx-kover + - Purpose: Kotlin code coverage toolset. + - License: Apache 2.0 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6b089545a..6811aed45 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -5,6 +5,7 @@ plugins { alias(libs.plugins.kotlin.android) alias(libs.plugins.kotlin.parcelize) alias(libs.plugins.kotlin.serialization) + alias(libs.plugins.kotlinx.kover) alias(libs.plugins.ksp) kotlin("kapt") } @@ -132,6 +133,43 @@ detekt { config.from(files("$rootDir/detekt-config.yml")) } +kover { + excludeJavaCode() +} + +koverReport { + filters { + excludes { + annotatedBy( + // Compose previews + "androidx.compose.ui.tooling.preview.Preview" + ) + classes( + // Navigation helpers + "*.*NavigationKt*", + // Composable singletons + "*.*ComposableSingletons*", + + // OS-level components + "com.x8bit.bitwarden.BitwardenApplication", + "com.x8bit.bitwarden.MainActivity*", + // Empty Composables + "com.x8bit.bitwarden.ui.platform.feature.splash.SplashScreenKt", + ) + packages( + // Dependency injection + "*.di", + // Models + "*.model", + // Custom UI components + "com.x8bit.bitwarden.ui.platform.components", + // Theme-related code + "com.x8bit.bitwarden.ui.platform.theme", + ) + } + } +} + tasks { getByName("check") { // Add detekt with type resolution to check diff --git a/build.gradle.kts b/build.gradle.kts index a4ba7c013..313f1b86c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,5 +3,6 @@ plugins { alias(libs.plugins.hilt) apply false alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.kotlin.parcelize) apply false + alias(libs.plugins.kotlinx.kover) apply false alias(libs.plugins.ksp) apply false } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 096478000..df2000b95 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -34,6 +34,7 @@ kotlin = "1.9.0" kotlinCompilerExtensionVersion = "1.5.1" kotlinxCoroutines = "1.7.3" kotlinxSerialization = "1.5.1" +kotlinxKover = "0.7.3" ksp = "1.9.0-1.0.11" mockk = "1.13.5" okhttp = "4.11.0" @@ -100,4 +101,5 @@ hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +kotlinx-kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kotlinxKover" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }