Share a code snippet for generating coverage report in GitHub Action

Maybe helpful for your project.

jobs:
  test:
    name: Tests on Linux
    runs-on: ubuntu-latest
    steps:

      # zig build and test
      
      - name: Install kcov
        run: sudo apt-get install -y kcov
      - name: Generate coverage reports
        run: kcov $PWD/kcov-out ./zig-cache/o/*/test
      - name: Upload coverage reports
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          directory: ./kcov-out/test
          verbose: true
          fail_ci_if_error: true

To utilize kcov, we need to generate a binary that incorporates DWARF debugging information. For example, ./zig-cache/o/*/test. If you use git submodule to manage dependencies, kcov will track those dependencies as well. To customize the coverage report, you can options like --include-pattern or --exclude-pattern to include or exclude specific files.

In this YAML, the coverage report is being uploaded to Codecov. However, you can choose to use a different platform for test coverage reporting. A small icon that can be embed in README.md, like

codecov

Ref: GitHub - SimonKagstrom/kcov: Code coverage tool for compiled programs, Python and Bash which uses debugging information to collect and report data without special compilation options

4 Likes