Skip to content

Feature/ag 14044 Testing sonar #15

Feature/ag 14044 Testing sonar

Feature/ag 14044 Testing sonar #15

Workflow file for this run

name: SonarQube Analysis (C#)
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
sonarcloud:
name: Analyze with SonarCloud
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v4
# Step 2: Setup .NET SDK
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'
# Step 3: Install SonarScanner for .NET
- name: Install SonarScanner for .NET
run: dotnet tool install --global dotnet-sonarscanner
# Step 4: Install ReportGenerator
- name: Install ReportGenerator
run: dotnet tool install --global dotnet-reportgenerator-globaltool
# Step 5: Restore dependencies
- name: Restore dependencies
run: dotnet restore
# Step 6: Run tests with coverage
- name: Run tests with coverage
run: |
dotnet test \
--collect:"XPlat Code Coverage" \
--results-directory ./TestResults
# Step 7: Convert coverage to OpenCover format
- name: Generate coverage report
run: |
reportgenerator \
-reports:./TestResults/**/coverage.cobertura.xml \
-targetdir:./CoverageResults \
-reporttypes:opencover
# Step 8: Run SonarCloud analysis
- name: Run SonarCloud analysis
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
dotnet sonarscanner begin \
/k:"autoguru-au_kv-push" \
/o:"autoguru-au" \
/d:sonar.login="${{ secrets.SONAR_TOKEN }}" \
/d:sonar.cs.opencover.reportsPaths="CoverageResults/coverage.opencover.xml"
dotnet build
dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"