Skip to content

ci: Improved test reports #330

ci: Improved test reports

ci: Improved test reports #330

Workflow file for this run

name: 'SonarCloud'
on:
workflow_dispatch: # To can dispatch manually
push:
branches:
- main
pull_request:
types: [opened, reopened, edited, synchronize]
branches:
- main
env:
SDK_VERSION: '8.0.203'
jobs:
sonar-scanner:
name: "Sonar scanner"
runs-on: ubuntu-latest
steps:
- name: "Setup .NET"
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.SDK_VERSION }}
- name: "Set up JDK"
uses: actions/[email protected]
with:
distribution: 'adopt'
java-version: '17'
- name: "Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: "Create cache directory"
run: mkdir -p ~/sonar/cache
- name: "Cache SonarCloud packages"
uses: actions/cache@v4
with:
path: ~/sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: "Cache SonarCloud scanner"
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: ./.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: "Install SonarCloud scanner"
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: |
mkdir -p ./.sonar/scanner
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
dotnet tool update dotnet-coverage --tool-path ./.sonar/scanner
- name: "Build and analyze"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: pwsh
run: |
./.sonar/scanner/dotnet-sonarscanner begin /k:"${{ secrets.SONAR_PROJECT_KEY }}" /o:"${{ secrets.SONAR_ORGANIZATION }}" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.projectBaseDir="$(pwd)"
dotnet build -c Release --no-incremental
./.sonar/scanner/dotnet-coverage collect "dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover -c Release --no-restore --no-build" -f xml -o "coverage.xml"
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"