Skip to content

Commit e9e603a

Browse files
committed
Test if token is available
WE2-964 Signed-off-by: Sven Mitt <[email protected]>
1 parent 17a44b0 commit e9e603a

File tree

1 file changed

+27
-40
lines changed

1 file changed

+27
-40
lines changed

.github/workflows/sonarcloud-analysis.yml

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,71 +9,58 @@ jobs:
99
runs-on: windows-latest
1010

1111
steps:
12+
- name: Unset CACHE_VERSION
13+
shell: powershell
14+
run: |
15+
Remove-Item Env:CACHE_VERSION -ErrorAction SilentlyContinue
16+
Write-Host "CACHE_VERSION has been unset"
17+
1218
- uses: actions/checkout@v4
1319
with:
1420
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
1521

1622
- name: Setup dotnet
1723
uses: actions/setup-dotnet@v4
1824
with:
19-
dotnet-version: 8.0.x # SDK Version to use.
25+
dotnet-version: 9.0.x # SDK Version to use.
2026

2127
- name: Set up JDK 21
2228
uses: actions/setup-java@v4
2329
with:
2430
distribution: temurin
2531
java-version: 21
2632

27-
- name: Cache Nuget packages
28-
uses: actions/cache@v4
29-
with:
30-
path: ~/.nuget/packages
31-
# Look to see if there is a cache hit for the corresponding requirements file
32-
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
33-
restore-keys: ${{ runner.os }}-nuget
34-
35-
- name: Install dependencies
36-
run: dotnet restore src/WebEid.Security.sln
37-
38-
- name: Cache SonarCloud packages
39-
uses: actions/cache@v4
40-
with:
41-
path: ~/.sonar/cache
42-
key: ${{ runner.os }}-sonar
43-
restore-keys: ${{ runner.os }}-sonar
44-
45-
- name: Cache SonarCloud scanner
46-
id: cache-sonar-scanner
47-
uses: actions/cache@v4
48-
with:
49-
path: .\.sonar\scanner
50-
key: ${{ runner.os }}-sonar-scanner
51-
restore-keys: ${{ runner.os }}-sonar-scanner
52-
5333
- name: Install SonarCloud scanner
54-
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
5534
shell: powershell
5635
run: |
57-
New-Item -Path .\.sonar\scanner -ItemType Directory
58-
dotnet tool install dotnet-sonarscanner --tool-path .\.sonar\scanner --version 10.1.2
36+
dotnet tool install --global dotnet-sonarscanner
37+
38+
- name: Create SonarQube.Analysis.xml
39+
shell: powershell
40+
run: |
41+
@"
42+
<?xml version="1.0" encoding="utf-8"?>
43+
<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">
44+
<Property Name="sonar.host.url">https://sonarcloud.io</Property>
45+
<Property Name="sonar.token">${{ secrets.SONAR_TOKEN }}</Property>
46+
<Property Name="sonar.password"></Property>
47+
</SonarQubeAnalysisProperties>
48+
"@ | Out-File -FilePath SQ.Analysis.xml -Encoding UTF8
5949
6050
- name: Build and analyze
6151
env:
6252
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
63-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
64-
CACHE_VERSION: ${{ vars.CACHE_VERSION }}
6553
shell: powershell
6654
run: |
67-
Write-Host "Branch: ${{ github.ref_name }}"
68-
Write-Host "Repository: ${{ github.repository }}"
69-
Write-Host "Event: ${{ github.event_name }}"
7055
if ("${{ secrets.SONAR_TOKEN }}" -eq "") {
7156
Write-Host "SONAR_TOKEN is missing"
7257
} else {
73-
Write-Host "SONAR_TOKEN is available -3 (length: $("${{ secrets.SONAR_TOKEN }}".Length))"
58+
Write-Host "SONAR_TOKEN is available -8 (length: $("${{ secrets.SONAR_TOKEN }}".Length))"
7459
}
75-
Remove-Item Env:CACHE_VERSION -ErrorAction SilentlyContinue
76-
.\.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"
77-
dotnet build --configuration Release --no-restore src/WebEid.Security.sln
60+
Write-Host "Branch: ${{ github.ref_name }}"
61+
Write-Host "CACHE_VERSION value: '$env:CACHE_VERSION'"
62+
dotnet sonarscanner begin /k:"web-eid_web-eid-authtoken-validation-dotnet" /o:"web-eid" /s:".\SQ.Analysis.xml" /d:sonar.verbose=true
63+
Get-ChildItem -Path ".\.sonarqube" -Recurse | Select-Object FullName, Length, LastWriteTime | Format-Table -AutoSize
64+
dotnet build --no-incremental --configuration Release src/WebEid.Security.sln
7865
dotnet test src/WebEid.Security.sln --logger trx --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover --results-directory "TestResults"
79-
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
66+
dotnet sonarscanner end

0 commit comments

Comments
 (0)