Test if token is available #448
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
| name: SonarCloud code analysis | |
| on: [push] | |
| jobs: | |
| analyze: | |
| name: Analyze | |
| if: github.repository == 'web-eid/web-eid-authtoken-validation-dotnet' | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis | |
| - name: Setup dotnet | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: 8.0.x # SDK Version to use. | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Cache Nuget packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.nuget/packages | |
| # Look to see if there is a cache hit for the corresponding requirements file | |
| key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} | |
| restore-keys: ${{ runner.os }}-nuget | |
| - name: Install dependencies | |
| run: dotnet restore src/WebEid.Security.sln | |
| - 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' | |
| shell: powershell | |
| run: | | |
| New-Item -Path .\.sonar\scanner -ItemType Directory | |
| dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner | |
| dotnet tool install dotnet-sonarscanner --tool-path .\.sonar\scanner --version 10.1.2 | |
| - name: Build and analyze | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| CACHE_VERSION: ${{ vars.CACHE_VERSION }} | |
| shell: powershell | |
| run: | | |
| Write-Host "Branch: ${{ github.ref_name }}" | |
| Write-Host "Repository: ${{ github.repository }}" | |
| Write-Host "Event: ${{ github.event_name }}" | |
| if ("${{ secrets.SONAR_TOKEN }}" -eq "") { | |
| Write-Host "SONAR_TOKEN is missing" | |
| } else { | |
| Write-Host "SONAR_TOKEN is available -2 (length: $("${{ secrets.SONAR_TOKEN }}".Length))" | |
| } | |
| Remove-Item Env:CACHE_VERSION -ErrorAction SilentlyContinue | |
| .\.sonar\scanner\dotnet-sonarscanner begin /k:"web-eid_web-eid-authtoken-validation-dotnet" /o:"web-eid" /d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" /d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx" /d:sonar.verbose=true /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" | |
| dotnet build --configuration Release --no-restore src/WebEid.Security.sln | |
| dotnet test src/WebEid.Security.sln --logger trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover --results-directory "TestResults" | |
| .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" |