|
9 | 9 | runs-on: windows-latest |
10 | 10 |
|
11 | 11 | 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 | +
|
12 | 18 | - uses: actions/checkout@v4 |
13 | 19 | with: |
14 | 20 | fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis |
15 | 21 |
|
16 | 22 | - name: Setup dotnet |
17 | 23 | uses: actions/setup-dotnet@v4 |
18 | 24 | with: |
19 | | - dotnet-version: 8.0.x # SDK Version to use. |
| 25 | + dotnet-version: 9.0.x # SDK Version to use. |
20 | 26 |
|
21 | 27 | - name: Set up JDK 21 |
22 | 28 | uses: actions/setup-java@v4 |
23 | 29 | with: |
24 | 30 | distribution: temurin |
25 | 31 | java-version: 21 |
26 | 32 |
|
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 |
44 | 37 |
|
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 | + } |
52 | 54 |
|
53 | | - - name: Install SonarCloud scanner |
54 | | - if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' |
| 55 | + - name: Create SonarQube.Analysis.xml |
55 | 56 | shell: powershell |
56 | 57 | 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 |
59 | 77 |
|
60 | 78 | - name: Build and analyze |
61 | 79 | env: |
62 | 80 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any |
63 | | - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
64 | | - CACHE_VERSION: ${{ vars.CACHE_VERSION }} |
65 | 81 | shell: powershell |
66 | 82 | run: | |
67 | | - Write-Host "Branch: ${{ github.ref_name }}" |
68 | | - Write-Host "Repository: ${{ github.repository }}" |
69 | | - Write-Host "Event: ${{ github.event_name }}" |
70 | 83 | if ("${{ secrets.SONAR_TOKEN }}" -eq "") { |
71 | 84 | Write-Host "SONAR_TOKEN is missing" |
72 | 85 | } 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))" |
74 | 87 | } |
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 |
78 | 93 | 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