test: cover untested branches to clear SonarCloud new-code coverage gate #4
This file contains hidden or 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
| # SonarCloud analysis with test coverage (CI-based scanner). | |
| # Requires a GitHub org-level secret SONAR_TOKEN, and Automatic Analysis turned OFF for | |
| # project PFalkowski_LoggerLite (SonarCloud > Administration > Analysis Method). | |
| name: SonarCloud | |
| on: | |
| push: | |
| branches: [ master ] | |
| pull_request: | |
| branches: [ master ] | |
| jobs: | |
| sonar: | |
| name: Build, test & analyze | |
| runs-on: ubuntu-latest | |
| # Skip PRs from forks — they can't access the SONAR_TOKEN secret. | |
| if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK (required by the scanner) | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 17 | |
| - name: Setup .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: 8.0.x | |
| - name: Cache SonarCloud packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| restore-keys: ${{ runner.os }}-sonar | |
| - name: Install scanner + coverage tools | |
| run: | | |
| dotnet tool install --global dotnet-sonarscanner | |
| dotnet tool install --global dotnet-coverage | |
| - name: Build, test (with coverage) & analyze | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| run: | | |
| dotnet-sonarscanner begin \ | |
| /k:"PFalkowski_LoggerLite" /o:"pfalkowski" \ | |
| /d:sonar.host.url="https://sonarcloud.io" \ | |
| /d:sonar.token="$SONAR_TOKEN" \ | |
| /d:sonar.exclusions="**/*TestHarness/**" \ | |
| /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml | |
| dotnet build --configuration Release | |
| dotnet-coverage collect "dotnet test --configuration Release --no-build" -f xml -o coverage.xml | |
| dotnet-sonarscanner end /d:sonar.token="$SONAR_TOKEN" |