scribe-org / Scribe-Android

Android app with keyboards for language learners
GNU General Public License v3.0
41 stars 40 forks source link

feat: Add Jacoco coverage and report generation #227

Closed albendz closed 2 weeks ago

albendz commented 3 weeks ago

Contributor checklist


Description

This change adds the Jacoco plugin to the app/gradle.build.kts file with configuration to generate coverage reports.

Additionally, this adds a step to the unit test Github workflow to use the generated coverage XML to create a comment on PRs. This is not configured to fail the PR build. Details: https://github.com/marketplace/actions/jacoco-report

One thing I wasn't able to configure is coverage verification checks and build time.

I followed details provided in this Medium article on adding coverage to Android projects: https://medium.com/@nachare.reena8/measure-your-codes-reach-integrating-jacoco-code-coverage-in-android-apps-with-kotlin-dsl-382d577864e7

Testing

./gradlew tasks output:

Reporting tasks
---------------
jacocoCoreDebugCodeCoverage - Generate Jacoco coverage reports for the CoreDebug build
jacocoCoreReleaseCodeCoverage - Generate Jacoco coverage reports for the CoreRelease build
jacocoFdroidDebugCodeCoverage - Generate Jacoco coverage reports for the FdroidDebug build
jacocoFdroidReleaseCodeCoverage - Generate Jacoco coverage reports for the FdroidRelease build

Verified ./gradlew jacocoCoreDebugCodeCoverage generates files with expected content:

The github action/workflow fails to post a comment to the PR when run. I'm not sure what's causing that. I've enabled debug logging on the action/workflow but someone with repo management permissions may need to help me understand what's going wrong with the token permissions.

Related issue

github-actions[bot] commented 3 weeks ago

Thank you for the pull request!

The Scribe team will do our best to address your contribution as soon as we can. The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the General and Android rooms once you're in. Also consider joining our bi-weekly Saturday dev syncs. It'd be great to have you!

Maintainer checklist

MahmoudMabrok commented 2 weeks ago

I think coverage reports not added to pr https://github.com/scribe-org/Scribe-Android/actions/runs/11618292715/job/32355382459?pr=227#step:5:182

I think we might need an action to write results here.

albendz commented 2 weeks ago

I think coverage reports not added to pr https://github.com/scribe-org/Scribe-Android/actions/runs/11618292715/job/32355382459?pr=227#step:5:182

I think we might need an action to write results here.

From what I can tell from the logs, the action is trying to write a comment to the PR and getting access denied. I think the default token has the right permissions based on what the other workflows in this repo are doing. When you say we might need an action to write results here, what do you mean? The step I'm adding is the action to write results here though I might be missing a step.

MahmoudMabrok commented 2 weeks ago

if coverage is added to PR, it is supposed to have it as comment on current PR.

andrewtavis commented 2 weeks ago

Yes I guess getting the coverage report as a comment to the PR would be nice :) I've experienced this with CodeCov in the past. Do you have a suggestion on how we could change it to add it in, @MahmoudMabrok?

MahmoudMabrok commented 2 weeks ago

I was to try on a fork and make it run, once finish I will share here.

Btw, we can merge and later we can enhance it.

andrewtavis commented 2 weeks ago

Please let us know if you have some ideas on the PR comment, @MahmoudMabrok :) Really appreciate your interest in the project and wanting to help out!