name: .NET Test Pipeline

on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checking out
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: SonarScanner for .NET 8 with pull request decoration support
        uses: highbyte/sonarscan-dotnet@v2.3.3
        with:
          sonarProjectKey: $(echo "${{ github.repository }}" | cut -d'/' -f2)
          sonarProjectName:  $(echo "${{ github.repository }}" | cut -d'/' -f2)
          sonarHostname:  ${{ secrets.SONAR_HOST_URL }}
          dotnetPreBuildCmd: dotnet nuget add source --name="Winsomnia" --username ${{ secrets.NUGET_USERNAME }} --password ${{ secrets.NUGET_PASSWORD }} --store-password-in-clear-text ${{ secrets.NUGET_ADDRESS }} && dotnet format --verify-no-changes --diagnostics -v diag --severity warn
          dotnetTestArguments: --logger trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
          dotnetBuildArguments: -c Release
          sonarBeginArguments: /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" -d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx"
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}