Skip to content

Commit 0b72d1f

Browse files
authored
Enable coverage report in PRs (#2946)
1 parent 2477877 commit 0b72d1f

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

.github/workflows/dotnetcore.yml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: .NET Core
22

3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
37
on:
48
push:
59
branches:
@@ -30,20 +34,43 @@ jobs:
3034
uses: actions/[email protected]
3135
with:
3236
dotnet-version: 6.0.x
33-
3437
- name: Setup .NET 8.0.x
3538
uses: actions/[email protected]
3639
with:
3740
dotnet-version: 8.0.x
38-
3941
- name: Setup .NET 9.0.x
4042
uses: actions/[email protected]
4143
with:
4244
dotnet-version: 9.0.100-rc.2.24474.11
4345

4446
- name: Run the tests
45-
run: dotnet test Wilson.sln
47+
run: dotnet test Wilson.sln --collect:"XPlat Code Coverage" --settings:./build/CodeCoverage.runsettings
48+
49+
- name: Create code coverage report
50+
run: |
51+
dotnet tool install -g dotnet-reportgenerator-globaltool
52+
reportgenerator -reports:./**/coverage.cobertura.xml -targetdir:CodeCoverage -reporttypes:'MarkdownSummaryGithub;Cobertura'
53+
54+
- name: Write Coverage to Job Summary
55+
shell: bash
56+
run: |
57+
cat CodeCoverage/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
58+
echo "COMMENT_CONTENT_ENV_VAR<<EOF" >> $GITHUB_ENV
59+
echo $(cat CodeCoverage/SummaryGithub.md) >> $GITHUB_ENV
60+
echo "EOF" >> $GITHUB_ENV
61+
62+
- name: Comment Coverage in PR
63+
uses: actions/github-script@v7
64+
id: comment
65+
with:
66+
script: |
67+
github.rest.issues.createComment({
68+
issue_number: context.issue.number,
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
body: process.env.COMMENT_CONTENT_ENV_VAR
72+
})
4673
4774
# Run baseline package validation
4875
- name: Pack
49-
run: dotnet pack Product.proj --no-restore --no-build
76+
run: dotnet pack Product.proj --no-restore --no-build

build/CodeCoverage.runsettings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ Included items must then not match any entries in the exclude list to remain inc
4040
<ModulePath>.*\microsoft.identitymodel.xml.dll</ModulePath>
4141
<ModulePath>.*\system.identitymodel.tokens.jwt.dll</ModulePath>
4242
</Include>
43+
<Exclude>
44+
<ModulePath>.*\\test\\.*</ModulePath>
45+
<ModulePath>.*Test\.dll</ModulePath>
46+
</Exclude>
4347
</ModulePaths>
4448
<Attributes>
4549
<Exclude>

build/commonTest.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
</ItemGroup>
4040

4141
<ItemGroup>
42+
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
43+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
44+
<PrivateAssets>all</PrivateAssets>
45+
</PackageReference>
4246
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="$(BannedApiAnalyzersVersion)">
4347
<PrivateAssets>all</PrivateAssets>
4448
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>

build/dependenciesTest.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<Project>
22
<PropertyGroup>
3+
<CoverletCollectorVersion>6.0.2</CoverletCollectorVersion>
34
<BannedApiAnalyzersVersion>3.3.4</BannedApiAnalyzersVersion>
45
<DotNetCoreAppRuntimeVersion>2.1.30</DotNetCoreAppRuntimeVersion>
56
<MicrosoftAzureKeyVaultCryptographyVersion>3.0.5</MicrosoftAzureKeyVaultCryptographyVersion>

0 commit comments

Comments
 (0)