0

Introduction

Currently, I'm working on a C project with CMake and Googletest. My project is on a GitHub repo.

I have configured my GitHub Workflow like this:

name: Build
on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    env:
      BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive
          fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
      - name: Install sonar-scanner and build-wrapper
        uses: SonarSource/sonarcloud-github-c-cpp@v1
      - name: Run build-wrapper
        run: |
          mkdir build
          cmake -S . -B build
          build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build build/ --config Release
      - name: Run sonar-scanner
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }} # Put the name of your token here
        run: |
          sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"

Problem

The problem, when I execute it the SonarCloud show 0% test coverage :

enter image description here

Question

Does someone know how we can configure the GitHub Actions for SonarCloud to include Googletest?

ThrowsError
  • 1,169
  • 1
  • 11
  • 43

1 Answers1

0

Does someone know how we can configure the GitHub Actions for SonarCloud to include Googletest?

In your current configuration, the coverage data is not being generated.

Follow this official guide to generate and report coverage data:

Apparently, for your use case, the most suitable example seems to be linux-cmake-gcovr-gh-actions-sc. It uses gcovr which generates the coverage report in the SonarQube format which you can send to SonarCloud.

For this, you need to update your CMakeFiles.txt and build.yml files according to these:

Also, see gcovr's Out-of-Source Builds with CMake.

Azeem
  • 11,148
  • 4
  • 27
  • 40