Skip to content

Test if token is available #452

Test if token is available

Test if token is available #452

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:
- name: Unset CACHE_VERSION
shell: powershell
run: |
Remove-Item Env:CACHE_VERSION -ErrorAction SilentlyContinue
Write-Host "CACHE_VERSION has been unset"
- 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: Install SonarCloud scanner
shell: powershell
run: |
dotnet tool install --global dotnet-coverage
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
if ("${{ secrets.SONAR_TOKEN }}" -eq "") {
Write-Host "SONAR_TOKEN is missing"
} else {
Write-Host "SONAR_TOKEN is available -5 (length: $("${{ secrets.SONAR_TOKEN }}".Length))"
}
Write-Host "Branch: ${{ github.ref_name }}"
Write-Host "CACHE_VERSION value: '$env:CACHE_VERSION'"
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.token="${{ secrets.SONAR_TOKEN }}" \
/d:sonar.host.url="https://sonarcloud.io" \
/d:sonar.verbose=true
dotnet build --no-incremental --configuration Release 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"
dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"