Skip to content

Commit b368a5c

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

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

.github/workflows/sonarcloud-analysis.yml

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,71 +9,86 @@ 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
33+
- name: Install SonarCloud scanner
34+
shell: powershell
35+
run: |
36+
dotnet tool install --global dotnet-sonarscanner
4437
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
38+
- name: Test SonarCloud API
39+
shell: powershell
40+
run: |
41+
$uri = 'https://sonarcloud.io/api/settings/values?component=unknown'
42+
$headers = @{
43+
'Authorization' = 'Bearer ${{ secrets.SONAR_TOKEN }}'
44+
}
45+
try {
46+
$response = Invoke-WebRequest -Uri $uri -Headers $headers -Method Get -UseBasicParsing
47+
Write-Host "HTTP Status Code: $($response.StatusCode)"
48+
}
49+
catch {
50+
$statusCode = $_.Exception.Response.StatusCode.value__
51+
Write-Host "HTTP Status Code: $statusCode"
52+
Write-Host "Error: $($_.Exception.Message)"
53+
}
5254
53-
- name: Install SonarCloud scanner
54-
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
55+
- name: Create SonarQube.Analysis.xml
5556
shell: powershell
5657
run: |
57-
New-Item -Path .\.sonar\scanner -ItemType Directory
58-
dotnet tool install dotnet-sonarscanner --tool-path .\.sonar\scanner --version 10.1.2
58+
@"
59+
<?xml version="1.0" encoding="utf-8"?>
60+
<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">
61+
<Property Name="sonar.host.url">https://sonarcloud.io</Property>
62+
<Property Name="sonar.token">${{ secrets.SONAR_TOKEN }}</Property>
63+
<Property Name="sonar.password"></Property>
64+
</SonarQubeAnalysisProperties>
65+
"@ | Out-File -FilePath SQ.Analysis.xml -Encoding UTF8
66+
67+
New-Item -ItemType Directory -Force -Path .sonarqube
68+
69+
@"
70+
<?xml version="1.0" encoding="utf-8"?>
71+
<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">
72+
<Property Name="sonar.host.url">https://sonarcloud.io</Property>
73+
<Property Name="sonar.token">${{ secrets.SONAR_TOKEN }}</Property>
74+
<Property Name="sonar.password"></Property>
75+
</SonarQubeAnalysisProperties>
76+
"@ | Out-File -FilePath .sonarqube\SQ.Analysis.xml -Encoding UTF8
5977
6078
- name: Build and analyze
6179
env:
6280
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
63-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
64-
CACHE_VERSION: ${{ vars.CACHE_VERSION }}
6581
shell: powershell
6682
run: |
67-
Write-Host "Branch: ${{ github.ref_name }}"
68-
Write-Host "Repository: ${{ github.repository }}"
69-
Write-Host "Event: ${{ github.event_name }}"
7083
if ("${{ secrets.SONAR_TOKEN }}" -eq "") {
7184
Write-Host "SONAR_TOKEN is missing"
7285
} else {
73-
Write-Host "SONAR_TOKEN is available -3 (length: $("${{ secrets.SONAR_TOKEN }}".Length))"
86+
Write-Host "SONAR_TOKEN is available -8 (length: $("${{ secrets.SONAR_TOKEN }}".Length))"
7487
}
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
88+
Write-Host "Branch: ${{ github.ref_name }}"
89+
Write-Host "CACHE_VERSION value: '$env:CACHE_VERSION'"
90+
dotnet sonarscanner begin /k:"web-eid_web-eid-authtoken-validation-dotnet" /o:"web-eid" /s:".\SQ.Analysis.xml" /d:sonar.verbose=true
91+
Get-ChildItem -Path ".\.sonarqube" -Recurse | Select-Object FullName, Length, LastWriteTime | Format-Table -AutoSize
92+
dotnet build --no-incremental --configuration Release src/WebEid.Security.sln
7893
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 }}"
94+
dotnet sonarscanner end

0 commit comments

Comments
 (0)