1- name : SonarCloud Analysis 
2- 
1+ name : SonarQube 
32on :
43  push :
54    branches :
65      - main 
76  pull_request :
8-     branches :
9-       - main 
10- 
7+     types : [opened, synchronize, reopened] 
118jobs :
129  build :
13-     name : Build and Analyze on SonarCloud 
14-     runs-on : ubuntu-latest 
15- 
10+     name : Build and analyze 
11+     runs-on : windows-latest 
1612    steps :
17-       - name : Checkout code 
18-         uses : actions/checkout@v3 
19- 
20-       - name : Setup .NET 
21-         uses : actions/setup-dotnet@v4 
13+       - name : Set up JDK 17 
14+         uses : actions/setup-java@v4 
15+         with :
16+           java-version : 17 
17+           distribution : ' zulu' #  Alternative distribution options are available.
18+       - uses : actions/checkout@v4 
19+         with :
20+           fetch-depth : 0   #  Shallow clones should be disabled for a better relevancy of analysis
21+       - name : Cache SonarQube Cloud packages 
22+         uses : actions/cache@v4 
2223        with :
23-           dotnet-version : ' 7.0.x' #  Use your project's .NET version
24- 
25-       - name : Install dependencies 
26-         run : dotnet restore 
27- 
28-       - name : Build 
29-         run : dotnet build --no-restore 
30- 
31-       - name : Test 
32-         run : dotnet test --no-build --verbosity normal 
33- 
34-       - name : SonarCloud Scan 
35-         uses : SonarSource/sonarcloud-github-action@v2 
24+           path : ~\sonar\cache 
25+           key : ${{ runner.os }}-sonar 
26+           restore-keys : ${{ runner.os }}-sonar 
27+       - name : Cache SonarQube Cloud scanner 
28+         id : cache-sonar-scanner 
29+         uses : actions/cache@v4 
3630        with :
37-           organization : ${{ secrets.SONAR_ORG }} 
38-           projectKey : ${{ secrets.SONAR_PROJECT_KEY }} 
39-           projectName : ${{ secrets.SONAR_PROJECT_NAME }} 
31+           path : .\.sonar\scanner 
32+           key : ${{ runner.os }}-sonar-scanner 
33+           restore-keys : ${{ runner.os }}-sonar-scanner 
34+       - name : Install SonarQube Cloud scanner 
35+         if : steps.cache-sonar-scanner.outputs.cache-hit != 'true' 
36+         shell : powershell 
37+         run : | 
38+           New-Item -Path .\.sonar\scanner -ItemType Directory 
39+           dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner 
40+ name : Build and analyze 
4041        env :
41-           SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }} 
42+           SONAR_TOKEN : ${{ secrets.SONAR_TOKEN }} 
43+         shell : powershell 
44+         run : | 
45+           .\.sonar\scanner\dotnet-sonarscanner begin /k:"sumanbdev_cSharp" /o:"sumanbdev" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" 
46+           dotnet build 
47+           .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" 
0 commit comments