Skip to content

Commit d795708

Browse files
Add SonarCloud analysis with code coverage (#12)
* Initial plan * Add SonarCloud analysis with code coverage Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> * Replace coverlet with Microsoft.Testing.Extensions.CodeCoverage Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> * Remove sonar-project.properties (incompatible with dotnet-sonarscanner) Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> * Switch coverage format to Cobertura for SonarCloud visibility Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> * Use sonar.coverageReportPaths for Cobertura coverage in SonarCloud Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> * Convert Cobertura to SonarQube generic coverage XML via reportgenerator Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: 304NotModified <5808377+304NotModified@users.noreply.github.com>
1 parent 5c2c308 commit d795708

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

.github/workflows/sonarcloud.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: SonarCloud
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
sonarcloud:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Setup .NET
22+
uses: actions/setup-dotnet@v4
23+
with:
24+
dotnet-version: 10.0.x
25+
26+
- name: Install SonarScanner for .NET
27+
run: |
28+
dotnet tool install --global dotnet-sonarscanner
29+
dotnet tool install --global dotnet-reportgenerator-globaltool
30+
31+
- name: Restore dependencies
32+
run: dotnet restore SLNX-validator.slnx
33+
34+
- name: Begin SonarCloud analysis
35+
env:
36+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
37+
run: |
38+
dotnet sonarscanner begin \
39+
/k:"slnx-validator" \
40+
/o:"304notmodified" \
41+
/d:sonar.token="${SONAR_TOKEN}" \
42+
/d:sonar.host.url="https://sonarcloud.io" \
43+
/d:sonar.coverageReportPaths="coverage/SonarQube.xml"
44+
45+
- name: Build
46+
run: dotnet build SLNX-validator.slnx --no-restore -c Release
47+
48+
- name: Test with coverage
49+
run: dotnet test --solution SLNX-validator.slnx --no-build -c Release --verbosity normal -- --coverage --coverage-output-format cobertura
50+
51+
- name: Convert coverage to SonarQube format
52+
run: reportgenerator -reports:"**/TestResults/**/*.cobertura.xml" -targetdir:coverage -reporttypes:SonarQube
53+
54+
- name: End SonarCloud analysis
55+
env:
56+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
57+
run: dotnet sonarscanner end /d:sonar.token="${SONAR_TOKEN}"

tests/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<ItemGroup>
1313
<PackageReference Include="TUnit" Version="1.17.*" />
14+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.*" />
1415
<PackageReference Include="AwesomeAssertions" Version="9.4.*" />
1516
</ItemGroup>
1617

0 commit comments

Comments
 (0)