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 | |
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 (Multiple Versions) | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: | | |
6.0.x | |
7.0.x | |
8.0.x | |
- name: Detect solution file | |
run: | | |
SOLUTION_FILE=$(find . -name "*.sln" | head -n 1) | |
if [ -z "$SOLUTION_FILE" ]; then | |
echo "❌ No solution file found. Exiting..." | |
exit 1 | |
fi | |
echo "✅ Found solution file: $SOLUTION_FILE" | |
echo "SOLUTION_FILE=$SOLUTION_FILE" >> $GITHUB_ENV | |
- name: Run tests with coverage | |
run: dotnet test "$SOLUTION_FILE" --collect:"XPlat Code Coverage" --logger trx --results-directory ./TestResults/ | |
- name: Upload test results (optional, for visibility) | |
uses: actions/upload-artifact@v4 | |
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.cobertura.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 test "$SOLUTION_FILE" --no-build | |
dotnet sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" |