Share a code snippet for generating coverage report in GitHub Action

Maybe helpful for your project.

    name: Tests on Linux
    runs-on: ubuntu-latest

      # 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
          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, like


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