Skip to content

Commit 8e8154a

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

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

.github/workflows/sonarcloud-analysis.yml

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ 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
@@ -24,56 +30,32 @@ jobs:
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-coverage
5937
6038
- name: Build and analyze
6139
env:
6240
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
6341
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
64-
CACHE_VERSION: ${{ vars.CACHE_VERSION }}
6542
shell: powershell
6643
run: |
67-
Write-Host "Branch: ${{ github.ref_name }}"
68-
Write-Host "Repository: ${{ github.repository }}"
69-
Write-Host "Event: ${{ github.event_name }}"
7044
if ("${{ secrets.SONAR_TOKEN }}" -eq "") {
7145
Write-Host "SONAR_TOKEN is missing"
7246
} else {
73-
Write-Host "SONAR_TOKEN is available -3 (length: $("${{ secrets.SONAR_TOKEN }}".Length))"
47+
Write-Host "SONAR_TOKEN is available -5 (length: $("${{ secrets.SONAR_TOKEN }}".Length))"
7448
}
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
49+
Write-Host "Branch: ${{ github.ref_name }}"
50+
Write-Host "CACHE_VERSION value: '$env:CACHE_VERSION'"
51+
dotnet sonarscanner begin \
52+
/k:"web-eid_web-eid-authtoken-validation-dotnet" \
53+
/o:"web-eid" \
54+
/d:sonar.cs.opencover.reportsPaths="**/TestResults/**/coverage.opencover.xml" \
55+
/d:sonar.cs.vstest.reportsPaths="**/TestResults/*.trx" \
56+
/d:sonar.token="${{ secrets.SONAR_TOKEN }}" \
57+
/d:sonar.host.url="https://sonarcloud.io" \
58+
/d:sonar.verbose=true
59+
dotnet build --no-incremental --configuration Release src/WebEid.Security.sln
7860
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 }}"
61+
dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"

0 commit comments

Comments
 (0)