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