Feature/ag 14044 Testing sonar #62
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: SonarQube Analysis (C#) | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
sonarqube: | |
name: Analyze with SonarQube | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Install SonarScanner for .NET | |
run: dotnet tool install --global dotnet-sonarscanner | |
- name: Install Coverlet.Console | |
run: dotnet tool install --global coverlet.console | |
- name: Restore dependencies | |
run: dotnet restore ./AutoGuru.KeyValuePush.sln | |
- name: Build tests | |
run: dotnet build ./src/KeyValuePush.Tests/KeyValuePush.Tests.csproj --configuration Debug --framework net8.0 | |
- name: Run tests with coverage | |
run: | | |
coverlet ./src/KeyValuePush.Tests/bin/Debug/net8.0/KeyValuePush.Tests.dll \ | |
--target "dotnet" \ | |
--targetargs "test ./src/KeyValuePush.Tests/KeyValuePush.Tests.csproj --no-build --framework net8.0 --logger trx --results-directory ./TestResults/" \ | |
--output ./TestResults/Coverage/ \ | |
--format opencover | |
- name: Upload test results (optional, for visibility in GitHub Actions) | |
uses: actions/upload-artifact@v3 | |
with: | |
name: TestResults | |
path: ./TestResults/ | |
- name: Run SonarQube analysis | |
env: | |
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: | | |
dotnet sonarscanner begin \ | |
/k:"${{ github.event.repository.name }}" \ | |
/n:"${{ github.event.repository.name }}" \ | |
/v:"${{ github.sha }}" \ | |
/d:sonar.cs.opencover.reportsPaths="./TestResults/Coverage/coverage.opencover.xml" \ | |
/d:sonar.inclusions="**/*.cs" \ | |
/d:sonar.exclusions="**/bin/**,**/obj/**" \ | |
/d:sonar.scanner.skipJreProvisioning=true \ | |
/d:sonar.verbose=true \ | |
/d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" \ | |
/d:sonar.login="${{ secrets.SONAR_TOKEN }}" | |
dotnet build ./AutoGuru.KeyValuePush.sln | |
dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" |