Skip to content

Commit

Permalink
Merge pull request #19936 from wordpress-mobile/configure_codecov
Browse files Browse the repository at this point in the history
Configure Codecov
  • Loading branch information
wzieba authored Jan 16, 2024
2 parents e82d46b + ea9cb25 commit 9427981
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 45 deletions.
12 changes: 9 additions & 3 deletions .buildkite/commands/run-unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
echo "--- 🧪 Testing"
set +e
if [ "$1" == "wordpress" ]; then
test_suite="testWordpressVanillaRelease"
test_suite="testWordpressVanillaRelease koverXmlReportWordpressVanillaRelease"
test_log_dir="WordPress/build/test-results/*/*.xml"
code_coverage_report="WordPress/build/reports/kover/reportWordpressVanillaRelease.xml"
elif [ "$1" == "processors" ]; then
test_suite=":libs:processors:test"
test_suite=":libs:processors:test :libs:processors:koverXmlReport"
test_log_dir="libs/processors/build/test-results/test/*.xml"
code_coverage_report="libs/processors/build/reports/kover/report.xml"
elif [ "$1" == "image-editor" ]; then
test_suite=":libs:image-editor:testReleaseUnitTest"
test_suite=":libs:image-editor:testReleaseUnitTest :libs:image-editor:koverXmlReportRelease"
test_log_dir="libs/image-editor/build/test-results/testReleaseUnitTest/*.xml"
code_coverage_report="libs/image-editor/build/reports/kover/reportRelease.xml"
else
echo "Invalid Test Suite! Expected 'wordpress', 'processors', or 'image-editor', received '$1' instead"
exit 1
Expand Down Expand Up @@ -46,4 +49,7 @@ echo "--- 🧪 Copying test logs for test collector"
mkdir buildkite-test-analytics
cp $test_log_dir buildkite-test-analytics

echo "--- ⚒️ Uploading code coverage"
.buildkite/commands/upload-code-coverage.sh $code_coverage_report

exit $TESTS_EXIT_STATUS
10 changes: 10 additions & 0 deletions .buildkite/commands/upload-code-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -eu

curl https://keybase.io/codecovsecurity/pgp_keys.asc | gpg --no-default-keyring --keyring trustedkeys.gpg --import
curl -Os https://uploader.codecov.io/latest/linux/codecov
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM
curl -Os https://uploader.codecov.io/latest/linux/codecov.SHA256SUM.sig
gpgv codecov.SHA256SUM.sig codecov.SHA256SUM
sha256sum -c codecov.SHA256SUM
chmod +x codecov
./codecov -t "$CODECOV_TOKEN" -f "$1"
8 changes: 8 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
comment:
require_changes: true
coverage:
status:
project: off
patch: off
codecov:
max_report_age: off
85 changes: 43 additions & 42 deletions config/gradle/code_coverage.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,49 @@ subprojects {
}
}
}

koverReport {
filters {
excludes {
packages(
'com.bumptech.glide',
'dagger.*',
'*.compose*',
'*.debug*',
'hilt_aggregated_deps',
'*.databinding',
'org.wordpress.android.modules',
'org.wordpress.android.widgets',
)

classes(
'*_Factory*',
'*Activity',
'*Activity$*',
'*Adapter',
'*Adapter$*',
'*BuildConfig',
'*DiffCallback*',
'*Dialog',
'*Dialog$*',
'*Fragment',
'*Fragment$*',
'*FragmentDirections*',
'*FragmentKt*',
'*Module',
'*Module_*',
'*View',
'*View$*',
'*ViewHolder',
'*ViewHolder$*',
'*ViewHolderKt*',
'*.Hilt_*',
'*HiltModules*',
'*_MembersInjector',
)
}
}
}
}
}

Expand All @@ -27,45 +70,3 @@ dependencies {
)
}

koverReport {
filters {
excludes {
packages(
'com.bumptech.glide',
'dagger.*',
'*.compose*',
'*.debug*',
'hilt_aggregated_deps',
'*.databinding',
'org.wordpress.android.modules',
'org.wordpress.android.widgets',
)

classes(
'*_Factory*',
'*Activity',
'*Activity$*',
'*Adapter',
'*Adapter$*',
'*BuildConfig',
'*DiffCallback*',
'*Dialog',
'*Dialog$*',
'*Fragment',
'*Fragment$*',
'*FragmentDirections*',
'*FragmentKt*',
'*Module',
'*Module_*',
'*View',
'*View$*',
'*ViewHolder',
'*ViewHolder$*',
'*ViewHolderKt*',
'*.Hilt_*',
'*HiltModules*',
'*_MembersInjector',
)
}
}
}
12 changes: 12 additions & 0 deletions docs/code-coverage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Code coverage

This project uses [Kover](https://github.com/Kotlin/kotlinx-kover) tool for generating code coverage metrics.
To run the code coverage report for the whole codebase, run `./gradlew koverHtmlReport` and open the HTML report at `WordPress/build/reports/kover/html/index.html`.

## Coverage exclusions

To get more precise results of the metrics, some classes are excluded from code coverage calculations. Those classes are e.g. Dagger/Hilt generated code, Acitivies, Fragments, databinding etc. A complete list of exclusions is available in the `config/gradle/code_coverage.gradle` file.

## Codecov

We also have `Codecov` integration for getting reports on each PR and observing trends. See [the dashboard](https://app.codecov.io/github/wordpress-mobile/WordPress-Android/) to get more insights.

0 comments on commit 9427981

Please sign in to comment.