name: SonarQube on: push: branches: - master pull_request: types: [opened, synchronize, reopened] jobs: build: name: Build and analyze runs-on: ubuntu-latest steps: - name: Set up JDK 17 uses: actions/setup-java@v4 with: java-version: 17 distribution: 'zulu' # Alternative distribution options are available. - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Setup .NET uses: actions/setup-dotnet@v4 with: dotnet-version: '9.0.x' - name: Install SonarQube Cloud scanner run: | mkdir -p ~/.sonar/scanner dotnet tool install dotnet-sonarscanner --tool-path ~/.sonar/scanner - name: Install dotnet-coverage run: | mkdir -p ~/.sonar/coverage dotnet tool install dotnet-coverage --tool-path ~/.sonar/coverage - name: Restore dependencies run: dotnet restore --verbosity normal - name: Build and analyze env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | echo "Starting SonarQube analysis..." echo "Current directory: $(pwd)" echo "Listing files:" ls -la # Check if SONAR_TOKEN is set if [ -z "$SONAR_TOKEN" ]; then echo "❌ SONAR_TOKEN is not set. Please configure the secret in repository settings." exit 1 fi echo "Installing SonarQube scanner..." ~/.sonar/scanner/dotnet-sonarscanner begin \ /k:"mrleo1nid_chatbot" \ /o:"mrleo1nid" \ /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml \ /d:sonar.scanner.skipJreProvisioning=true \ /d:sonar.host.url=https://sonarcloud.io echo "Building project..." dotnet build --verbosity normal --no-incremental echo "Running tests and collecting coverage..." dotnet test --verbosity normal --logger "trx;LogFileName=test-results.trx" --results-directory ./TestResults --collect:"XPlat Code Coverage" --settings coverlet.runsettings echo "Ending SonarQube analysis..." ~/.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"