Skip to content

Test if token is available #471

Test if token is available

Test if token is available #471

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: 9.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-sonarscanner
- name: Create SonarQube.Analysis.xml
shell: powershell
run: |
@"
<?xml version="1.0" encoding="utf-8"?>
<SonarQubeAnalysisProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">
<Property Name="sonar.host.url">https://sonarcloud.io</Property>
<Property Name="sonar.token">${{ secrets.SONAR_TOKEN }}</Property>
<Property Name="sonar.password"></Property>
</SonarQubeAnalysisProperties>
"@ | Out-File -FilePath SQ.Analysis.xml -Encoding UTF8
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
shell: powershell
run: |
if ("${{ secrets.SONAR_TOKEN }}" -eq "") {
Write-Host "SONAR_TOKEN is missing"
} else {
Write-Host "SONAR_TOKEN is available -8 (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" /s:".\SQ.Analysis.xml" /d:sonar.verbose=true
Get-ChildItem -Path ".\.sonarqube" -Recurse | Select-Object FullName, Length, LastWriteTime | Format-Table -AutoSize
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