Hi Team,
i tried a lot but still not able to get the code coverage. its still 0. could you please help. its in github actions dotnet framework . please find the below yaml file
name: Sonarqube
on:
push:
branches:
- feature/sonar2405
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build
runs-on: windows-runner
permissions: read-all
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
- name: Cache SonarQube packages
uses: actions/cache@v1
with:
path: ~\.sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarQube scanner
id: cache-sonar-scanner
uses: actions/cache@v2
with:
path: ./.sonar/scanner
key: ${{ runner.os }}-sonar-scanner-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-sonar-scanner-
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.203' # Specify the exact version of the .NET SDK
- name: Verify .NET installation
shell: powershell
run: |
dotnet --version
$env:PATH += ";C:\Program Files\dotnet"
[System.Environment]::SetEnvironmentVariable("PATH", $env:PATH, [System.EnvironmentVariableTarget]::Process)
- name: Install Coverlet and ReportGenerator
run: |
dotnet tool list -g | Select-String 'dotnet-reportgenerator-globaltool'
dotnet tool install --global dotnet-reportgenerator-globaltool
if (-not (dotnet tool list -g | Select-String 'coverlet.console')) {
dotnet tool install --global coverlet.console
}
echo "$env:USERPROFILE\.dotnet\tools" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Verify Coverlet Installation
run: coverlet --version
- name: Install SonarQube scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: |
dotnet --version
if (-Not (Test-Path -Path .\.sonar\scanner)) {
New-Item -Path .\.sonar\scanner -ItemType Directory
}
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
$Env:PATH += ";$Env:USERPROFILE\.dotnet\tools"
- name: Build and analyze
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"nseb-gess_ey7866-d340-4d77-8209-ch78t" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" /d:sonar.cs.opencover.reportsPaths="**/coverage.opencover.xml" /d:sonar.exclusions="**/ClassDiagram1.cd,**/DesignTimeResolveAssemblyReferencesInput.cache,**/RFE.edmx.sql"
dotnet build
dotnet test --collect:"XPlat Code Coverage"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: Report code coverage
if: always()
uses: actions/upload-artifact@v2
with:
name: code-coverage-report
path: './coverage.opencover.xml'