Skip to content

Commit 5e3d9d3

Browse files
authored
Merge pull request #1092 from microsoft/feature/sonarcloud
feature/sonarcloud
2 parents b530580 + 65e92bf commit 5e3d9d3

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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" /o:"microsoft" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="test/**/coverage.opencover.xml"
75+
dotnet workload restore
76+
dotnet build
77+
dotnet test Microsoft.OpenApi.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
78+
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"

test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12+
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
1216
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
1317
<PackageReference Include="Moq" Version="4.18.3" />
1418
<PackageReference Include="xunit" Version="2.4.2" />

test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@
253253
</ItemGroup>
254254

255255
<ItemGroup>
256+
<PackageReference Include="coverlet.collector" Version="3.2.0">
257+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
258+
<PrivateAssets>all</PrivateAssets>
259+
</PackageReference>
260+
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
261+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
262+
<PrivateAssets>all</PrivateAssets>
263+
</PackageReference>
256264
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
257265
<PackageReference Include="FluentAssertions" Version="6.8.0">
258266
</PackageReference>

test/Microsoft.OpenApi.SmokeTests/Microsoft.OpenApi.SmokeTests.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11+
<PackageReference Include="coverlet.collector" Version="3.2.0">
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
<PrivateAssets>all</PrivateAssets>
14+
</PackageReference>
15+
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
<PrivateAssets>all</PrivateAssets>
18+
</PackageReference>
1119
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
1220
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
1321
<PackageReference Include="xunit" Version="2.4.2" />

test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18+
<PackageReference Include="coverlet.collector" Version="3.2.0">
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
<PrivateAssets>all</PrivateAssets>
21+
</PackageReference>
22+
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24+
<PrivateAssets>all</PrivateAssets>
25+
</PackageReference>
1826
<PackageReference Include="FluentAssertions" Version="6.8.0" />
1927
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
2028
<PackageReference Include="Moq" Version="4.18.3" />

0 commit comments

Comments
 (0)