Kotlin code coverage in CI/CD

I ran in to a few problems with CI/CD for code coverage in kotlin recently. The toolchain I was using was

  • kotlin
  • kover
  • gradle
  • github actions

Kover does have a JaCoCo output format which would have enabled using the JaCoCo-report action, however I kept hitting a stack trace when trying to use the JaCoCo output format. The message was:

Can't add different class with same name: BuildConfig

The details of the issue are here. The gradle kover plugin also supports the IntelliJ output format in XML. I’ve done some action development in the past so I thought I’d put together an action to use for automating coverage in CI / CD.

Composite actions make the whole development process really easy. Essentially I just leveraged the setup-java action and some bash tools to produce a fully working action in a single yaml file!

You can use the action now, it’s fully operational and available in the GitHub Action Market place here

Usage

name: Test coverage

on:
  pull_request:

jobs:

  collect_coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: stevenleadbeater/kotlin-kover-action@v1.0.0
        id: kover-tests
        with:
          coverage-threshold: 80
          repo-token: ${{ secrets.GITHUB_TOKEN }}
      - name: Check coverage
        if: ${{(steps.kover-tests.outputs.line-coverage) < 80}}
        shell: bash
        run: exit "Line coverage expected to be > 80 but was ${{steps.kover-tests.outputs.line-coverage}}"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: