|
| 1 | +name: SonarQube Analysis (C#) |
| 2 | + |
| 3 | +on: push |
| 4 | + |
| 5 | +jobs: |
| 6 | + sonarqube: |
| 7 | + name: Analyze with SonarQube |
| 8 | + runs-on: ubuntu-latest |
| 9 | + |
| 10 | + steps: |
| 11 | + - name: Checkout repository |
| 12 | + uses: actions/checkout@v4 |
| 13 | + with: |
| 14 | + fetch-depth: 0 |
| 15 | + |
| 16 | + - name: Setup .NET |
| 17 | + uses: actions/setup-dotnet@v4 |
| 18 | + with: |
| 19 | + dotnet-version: '8.0.x' |
| 20 | + |
| 21 | + - name: Restore dependencies |
| 22 | + run: dotnet restore |
| 23 | + |
| 24 | + - name: Build project |
| 25 | + run: dotnet build --configuration Debug |
| 26 | + |
| 27 | + - name: Run tests and generate coverage |
| 28 | + run: | |
| 29 | + dotnet test --collect:"XPlat Code Coverage" --logger trx --results-directory ./TestResults/ |
| 30 | +
|
| 31 | + - name: Upload test results (optional, for visibility) |
| 32 | + uses: actions/upload-artifact@v4 |
| 33 | + with: |
| 34 | + name: TestResults |
| 35 | + path: ./TestResults/ |
| 36 | + |
| 37 | + - name: Run SonarQube analysis |
| 38 | + env: |
| 39 | + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} |
| 40 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 41 | + run: | |
| 42 | + dotnet sonarscanner begin \ |
| 43 | + /k:"${{ github.event.repository.name }}" \ |
| 44 | + /n:"${{ github.event.repository.name }}" \ |
| 45 | + /v:"${{ github.sha }}" \ |
| 46 | + /d:sonar.cs.opencover.reportsPaths="./TestResults/**/coverage.cobertura.xml" \ |
| 47 | + /d:sonar.inclusions="**/*.cs" \ |
| 48 | + /d:sonar.exclusions="**/bin/**,**/obj/**" \ |
| 49 | + /d:sonar.scanner.skipJreProvisioning=true \ |
| 50 | + /d:sonar.verbose=true \ |
| 51 | + /d:sonar.host.url="${{ secrets.SONAR_HOST_URL }}" \ |
| 52 | + /d:sonar.login="${{ secrets.SONAR_TOKEN }}" |
| 53 | + dotnet build |
| 54 | + dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" |
0 commit comments