Skip to content

Commit 4ead628

Browse files
authored
Add code coverage and sonarcloud to CI
* Add basic code coverage to pipeline. * Enable sourcelink in nuget packages. * Enable SonarScanner Resolves #52
1 parent 236397b commit 4ead628

File tree

8 files changed

+54
-21
lines changed

8 files changed

+54
-21
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
"commands": [
88
"dotnet-format"
99
]
10+
},
11+
"dotnet-sonarscanner": {
12+
"version": "4.9.0",
13+
"commands": [
14+
"dotnet-sonarscanner"
15+
]
16+
},
17+
"gitversion.tool": {
18+
"version": "5.3.6",
19+
"commands": [
20+
"dotnet-gitversion"
21+
]
1022
}
1123
}
1224
}

.editorconfig

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,14 @@ root = true
33
[*]
44
insert_final_newline = true
55
indent_style = space
6-
indent_size = 4
6+
indent_size = 2
77
trim_trailing_whitespace = true
88

99
[*.md]
1010
trim_trailing_whitespace = false
1111

12-
[*.props]
13-
indent_size = 2
14-
15-
[*.targets]
16-
indent_size = 2
17-
18-
[*.csproj]
19-
indent_size = 2
20-
2112
[*.cs]
13+
indent_size = 4
2214
dotnet_style_qualification_for_field = false:warning
2315
dotnet_style_qualification_for_property = false:warning
2416
dotnet_style_qualification_for_method = false:warning

.github/workflows/dotnetcore.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ env:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12-
if: github.event_name == 'push'
1312
steps:
1413
- name: Dump GitHub context
1514
env:
@@ -22,36 +21,46 @@ jobs:
2221
- name: Setup .NET Core
2322
uses: actions/setup-dotnet@v1
2423
with:
25-
dotnet-version: 3.1.300
24+
dotnet-version: 3.1.301
2625
- name: Restore dotnet tools
2726
run: dotnet tool restore
27+
- name: Prepare sonarqube
28+
run: dotnet sonarscanner begin -d:sonar.host.url=https://sonarcloud.io -organization:dnperfors-github -key:dnperfors_TestableHttpClient -version:`dotnet gitversion -showvariable semver` -d:sonar.cs.opencover.reportsPaths=**/coverage.opencover.xml -d:sonar.login=${{secrets.SONARCLOUD_TOKEN}}
2829
- name: Restore dependencies
2930
run: dotnet restore
3031
- name: Build source code
3132
run: dotnet build --configuration Release --no-restore
3233
- name: Test with dotnet
33-
run: dotnet test --configuration Release --no-build
34+
run: dotnet test --configuration Release --no-build --collect="Code Coverage"
35+
- name: Upload sonarqube results
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
run: dotnet sonarscanner end -d:sonar.login=${{secrets.SONARCLOUD_TOKEN}}
3439
- name: Check source file format
3540
run: dotnet format --folder . --check --dry-run # --folder is used to supress warnings: https://github.com/dotnet/format/issues/584
3641
- name: Pack
3742
run: dotnet pack --output ./artifacts --configuration Release --no-build
38-
- uses: actions/upload-artifact@v1
43+
- uses: actions/upload-artifact@v2
3944
with:
4045
name: artifacts
4146
path: ./artifacts
47+
- uses: actions/upload-artifact@v2
48+
with:
49+
name: coverage
50+
path: ./**/TestResults/**/coverage.opencover.xml
4251

4352
publish:
4453
runs-on: ubuntu-latest
4554
needs: build
4655
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
4756
steps:
4857
- name: Checkout
49-
uses: actions/checkout@v1
58+
uses: actions/checkout@v2
5059
- name: Setup .NET Core
5160
uses: actions/setup-dotnet@v1
5261
with:
53-
dotnet-version: 3.1.300
54-
- uses: actions/download-artifact@v1
62+
dotnet-version: 3.1.301
63+
- uses: actions/download-artifact@v2
5564
with:
5665
name: artifacts
5766
path: ./artifacts

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,6 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
352+
# SonarQube scans
353+
.sonarqube

Directory.Build.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1414
<DevelopmentDependency>false</DevelopmentDependency>
1515
<PackageLicenseExpression>MIT</PackageLicenseExpression>
16+
17+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
18+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
1619
<IncludeSymbols>true</IncludeSymbols>
1720
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
21+
1822
<IncludeSource>true</IncludeSource>
1923
<RepositoryUrl>https://github.com/dnperfors/TestableHttpClient</RepositoryUrl>
2024
<RepositoryType>git</RepositoryType>

Directory.Build.targets

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<Project>
22
<ItemGroup>
3-
<PackageReference Include="GitVersionTask" Version="5.3.6">
4-
<PrivateAssets>all</PrivateAssets>
5-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
6-
</PackageReference>
3+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
4+
<PackageReference Include="GitVersionTask" Version="5.3.6" PrivateAssets="All" />
75
</ItemGroup>
86
</Project>

test/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
33
<PropertyGroup>
44
<IsPackable>false</IsPackable>
5+
<RunSettingsFilePath>$(MSBuildThisFileDirectory)/coverlet.runsettings</RunSettingsFilePath>
56
</PropertyGroup>
67
</Project>

test/coverlet.runsettings

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<RunSettings>
3+
<DataCollectionRunSettings>
4+
<DataCollectors>
5+
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CoverletCodeCoverage/1.0">
6+
<Configuration>
7+
<Format>opencover</Format>
8+
<ExcludeByAttribute>GeneratedCodeAttribute,CompilerGeneratedAttribute</ExcludeByAttribute>
9+
<UseSourceLink>false</UseSourceLink>
10+
</Configuration>
11+
</DataCollector>
12+
</DataCollectors>
13+
</DataCollectionRunSettings>
14+
</RunSettings>

0 commit comments

Comments
 (0)