1+ name : Sonarcloud 
2+ on :
3+   workflow_dispatch :
4+   push :
5+     branches :
6+       - main 
7+     paths-ignore : ['.vscode/**'] 
8+   pull_request :
9+     types : [opened, synchronize, reopened] 
10+     paths-ignore : ['.vscode/**'] 
11+ 
12+ env :
13+   SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }} 
14+ 
15+ jobs :
16+   checksecret :
17+     name : check if SONAR_TOKEN is set in github secrets 
18+     runs-on : ubuntu-latest 
19+     outputs :
20+       is_SONAR_TOKEN_set : ${{ steps.checksecret_job.outputs.is_SONAR_TOKEN_set }} 
21+     steps :
22+       - name : Check whether unity activation requests should be done 
23+         id : checksecret_job 
24+         run : | 
25+             echo "is_SONAR_TOKEN_set=${{ env.SONAR_TOKEN != '' }}" >> $GITHUB_OUTPUT 
26+ build :
27+     needs : [checksecret] 
28+     if : needs.checksecret.outputs.is_SONAR_TOKEN_set == 'true' 
29+     name : Build 
30+     runs-on : windows-latest 
31+     steps :
32+       - name : Set up JDK 11 
33+         uses : actions/setup-java@v3 
34+         with :
35+           distribution : ' adopt' 
36+           java-version : 11 
37+       - name : Setup .NET 5  #  At the moment the scanner requires dotnet 5 https://www.nuget.org/packages/dotnet-sonarscanner
38+         uses : actions/setup-dotnet@v3 
39+         with :
40+           dotnet-version : 5.0.x 
41+       - name : Setup .NET 
42+         uses : actions/setup-dotnet@v3 
43+         with :
44+           dotnet-version : 7.0.x 
45+       - uses : actions/checkout@v3 
46+         with :
47+           fetch-depth : 0   #  Shallow clones should be disabled for a better relevancy of analysis
48+       - name : Cache SonarCloud packages 
49+         uses : actions/cache@v3 
50+         with :
51+           path : ~/.sonar/cache 
52+           key : ${{ runner.os }}-sonar 
53+           restore-keys : ${{ runner.os }}-sonar 
54+       - name : Cache SonarCloud scanner 
55+         id : cache-sonar-scanner 
56+         uses : actions/cache@v3 
57+         with :
58+           path : ./.sonar/scanner 
59+           key : ${{ runner.os }}-sonar-scanner 
60+           restore-keys : ${{ runner.os }}-sonar-scanner 
61+       - name : Install SonarCloud scanner 
62+         if : steps.cache-sonar-scanner.outputs.cache-hit != 'true' 
63+         shell : pwsh 
64+         run : | 
65+           New-Item -Path ./.sonar/scanner -ItemType Directory 
66+           dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner 
67+ name : Build and analyze 
68+         env :
69+           GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}   #  Needed to get PR information, if any
70+           CollectCoverage : true 
71+           CoverletOutputFormat : ' opencover' #  https://github.com/microsoft/vstest/issues/4014#issuecomment-1307913682
72+         shell : pwsh 
73+         run : | 
74+           ./.sonar/scanner/dotnet-sonarscanner begin /k:"microsoft_OpenAPI.NET.OData" /o:"microsoft" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="test/**/coverage.net7.0.opencover.xml" 
75+           dotnet workload restore 
76+           dotnet build 
77+           dotnet test Microsoft.OpenApi.OData.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover 
78+           ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" 
0 commit comments