Skip to content

Commit

Permalink
Code coverage with coverlet and codecov (#3004)
Browse files Browse the repository at this point in the history
* Added Coverlet to Sentry.Tests (experimental)

* Moved coverlet config to Directory.Build.props

* Added parameter to dotnet test so code coverage is collected

* Added github action to upload code coverage to codecov (currently disabled)

* Update .github/workflows/build.yml

* Update .github/workflows/build.yml

* Update .github/workflows/build.yml

* badge

* Update .github/workflows/build.yml

* Apply suggestions from code review

* Update test/Directory.Build.props

* fetch depth 2

* Update .gitignore

* Switched back to opencover output format

* Codecov informational only

---------

Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
  • Loading branch information
jamescrosswell and bruno-garcia authored Jan 8, 2024
1 parent f63da1d commit cfad9a5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ coverage:
changes: false
project:
default:
threshold: 5%
informational: true
patch: off
ignore:
- "benchmarks/**/*"
- "modules/**/*"
- "samples/**/*"
- "test/**/*"
range: 0..100
round: down
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 2 # default is 1 and codecov needs > 1

# We use macOS for the final publishing build so we we get all the iOS/macCatalyst targets in the packages
- name: Set Environment Variables
Expand Down Expand Up @@ -113,7 +114,10 @@ jobs:
run: dotnet build Sentry-CI-Build-${{ runner.os }}.slnf -c Release --no-restore --nologo -flp:logfile=build.log -p:CopyLocalLockFileAssemblies=true

- name: Test
run: dotnet test Sentry-CI-Build-${{ runner.os }}.slnf -c Release --no-build --nologo -l GitHubActions -l "trx;LogFilePrefix=testresults_${{ runner.os }}"
run: dotnet test Sentry-CI-Build-${{ runner.os }}.slnf -c Release --no-build --nologo -l GitHubActions -l "trx;LogFilePrefix=testresults_${{ runner.os }}" /p:CollectCoverage=true

- name: Upload code coverage
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d

- name: Upload build and test outputs
if: failure()
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ codecov.sh
lcov.info
bin/
obj/
**/coverage/*.xml
**/coverage/*.json
.DS_Store
Thumbs.db
**/BenchmarkDotNet.Artifacts/*.log
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Sentry SDK for .NET
===========

[![build](https://github.com/getsentry/sentry-dotnet/workflows/build/badge.svg?branch=main)](https://github.com/getsentry/sentry-dotnet/actions?query=branch%3Amain)
[![codecov](https://codecov.io/gh/getsentry/sentry-dotnet/branch/main/graph/badge.svg)](https://codecov.io/gh/getsentry/sentry-dotnet)
[![Discord Chat](https://img.shields.io/discord/621778831602221064?logo=discord&logoColor=ffffff&color=7389D8)](https://discord.gg/PXa5Apfe7K)


Expand Down
2 changes: 1 addition & 1 deletion build.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dotnet build Sentry.sln -c Release
dotnet test Sentry.sln -c Release --no-build
dotnet test Sentry.sln -c Release --no-build /p:CollectCoverage=true
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dotnet build Sentry.sln -c Release
dotnet test Sentry.sln -c Release --no-build
dotnet test Sentry.sln -c Release --no-build /p:CollectCoverage=true
14 changes: 14 additions & 0 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,22 @@
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.2" />
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="19.2.29" />
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>


<!-- Configuration for Coverlet code coverage -->
<PropertyGroup Condition="'$(CollectCoverage)' == 'true'">
<Exclude>[Sentry.Protocol.Test*]*,[xunit.*]*,[System.*]*,[Microsoft.*]*,[Sentry.Test*]*</Exclude>
<CoverletOutput>./coverage/</CoverletOutput>
<CoverletOutputFormat>opencover</CoverletOutputFormat>
<!-- Deterministic report not supported by openCover reporter -->
<DeterministicReport>false</DeterministicReport>
</PropertyGroup>

<!-- only non-platform-specific projects should include these packages -->
<ItemGroup Condition="'$(TargetPlatformIdentifier)'==''">
<PackageReference Include="Verify.Xunit" Version="20.0.0" />
Expand Down

0 comments on commit cfad9a5

Please sign in to comment.