Sonar CodeCoverage Github Action Not Appearing

Hello,

I’m using github action with SonarCloud on my .NET project, however even after many hours of search I have not managed to have my code covergae appearing in my Sonar analysis

Here is my Github Action yaml:

# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
  pull_request:
    branches: [ "main" ]
  push: 
    branches: ["main"]
  
jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: 6.0.x
    - name: Restore workload
      working-directory: ./src
      run: dotnet workload restore
    - name: Restore dependencies
      working-directory: ./src
      run: dotnet restore
    - name: Build
      working-directory: ./src
      run: dotnet build --no-restore
    - name: Install Dotnet Code Coverage
      working-directory: ./src
      run: dotnet tool install --global dotnet-coverage
    - name: Test with compute code coverage
      working-directory: ./src
      run:  dotnet test --collect "Code Coverage"
    - name: SonarCloud Scan
  # You may pin to the exact commit or the version.
  # uses: SonarSource/sonarcloud-github-action@49e6cd3b187936a73b8280d59ffd9da69df63ec9
      uses: SonarSource/sonarcloud-github-action@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
      with:
        projectBaseDir: .  

Hi,

While I see the test coverage being collected, I don’t see the begin step before it, or anywhere in the YAML. The docs should help.

 
Ann

Hello Ann,

Firstly thanks for the answer.I read the link you provided me and after a few adjustments I manage to have the action running. However at the final I still get the following error:

Here is my github action file after adjustments:

# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
  pull_request:
    branches: [ "main" ]
  push: 
    branches: ["main"]
  
jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Setup .NET
      uses: actions/setup-dotnet@v3
      with:
        dotnet-version: 6.0.x
    - name: Restore workload
      working-directory: ./src
      run: dotnet workload restore
    - name: Restore dependencies
      working-directory: ./src
      run: dotnet restore
    - name: Build
      working-directory: ./src
      run: dotnet build --no-restore
    - name: Install Dotnet Code Coverage
      working-directory: ./src
      run: dotnet tool install --global dotnet-coverage
    - name: Install sonarscanner
      run: dotnet tool install --global dotnet-sonarscanner
    - name: Test with compute code coverage
      working-directory: ./src
      run:  |
            dotnet sonarscanner begin /k:"elimbime_SuperWebScraper" /o:"elimbime" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.host.url="https://sonarcloud.io"
            dotnet build --no-incremental
            dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
            dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
    - name: SonarCloud Scan
  # You may pin to the exact commit or the version.
  # uses: SonarSource/sonarcloud-github-action@49e6cd3b187936a73b8280d59ffd9da69df63ec9
      uses: SonarSource/sonarcloud-github-action@master
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
      with:
        projectBaseDir: .  

Hi,

This guide should help.

 
Ann

Hi Ann,

Sorry for the delay but I’m a bit at a loss here, I use d Github Actions provided by Sonar and I don’t think I can run the command that was provided in the link.
Furthermore I supposed that it was supposed to work Sonar and sonarscanner were to work together.
Is there a simple tutorial that shows how to configure my Sonar analysis with code coverage in Github for .NET project ?

Hi,

The link I sent relates directly to the error message in your screenshot: you’re trying to use a version of Java that’s too old.

Have you tried the in-product wizard for new project configuration?

 
Ann