Skip to content

Commit 153cb3b

Browse files
authored
display code coverage as PR comments (#3107)
* display code coverage as PR comments * remove collector reference from projects reporting zeros
1 parent 50bdedf commit 153cb3b

File tree

7 files changed

+41
-25
lines changed

7 files changed

+41
-25
lines changed

.github/workflows/dotnetcore.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: "Run unit tests"
22

3+
permissions:
4+
contents: read
5+
pull-requests: write
6+
37
on:
48
push:
59
branches:
@@ -58,9 +62,34 @@ jobs:
5862

5963
- name: Test with .NET 7.0.x
6064
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net7.0 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~TokenAcquirerTests)"
61-
65+
6266
- name: Test with .NET 8.0.x
63-
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net8.0 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~TokenAcquirerTests)"
67+
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net8.0 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --collect "Xplat Code Coverage" --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~TokenAcquirerTests)"
68+
69+
- name: Create code coverage report
70+
run: |
71+
dotnet tool install -g dotnet-reportgenerator-globaltool
72+
reportgenerator -reports:./**/coverage.cobertura.xml -targetdir:CodeCoverage -reporttypes:'MarkdownSummaryGithub;Cobertura'
73+
74+
- name: Write Coverage to Job Summary
75+
shell: bash
76+
run: |
77+
cat CodeCoverage/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
78+
echo "COMMENT_CONTENT_ENV_VAR<<EOF" >> $GITHUB_ENV
79+
echo $(cat CodeCoverage/SummaryGithub.md) >> $GITHUB_ENV
80+
echo "EOF" >> $GITHUB_ENV
81+
82+
- name: Comment Coverage in PR
83+
uses: actions/github-script@v7
84+
id: comment
85+
with:
86+
script: |
87+
github.rest.issues.createComment({
88+
issue_number: context.issue.number,
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
body: process.env.COMMENT_CONTENT_ENV_VAR
92+
})
6493
6594
- name: Test with .NET 9.0.x
6695
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f net9.0 -v normal -p:FROM_GITHUB_ACTION=true -p:TargetNet9=True --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)&(FullyQualifiedName!~TokenAcquirerTests)"
@@ -73,4 +102,3 @@ jobs:
73102

74103
- name: Test with .NET Standard 2.0
75104
run: dotnet test --no-restore --no-build Microsoft.Identity.Web.sln -f netstandard2.0 -v normal -p:FROM_GITHUB_ACTION=true --configuration Release --filter "(FullyQualifiedName!~Microsoft.Identity.Web.Test.Integration)&(FullyQualifiedName!~WebAppUiTests)&(FullyQualifiedName!~IntegrationTests)"
76-

tests/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<XunitExtensibilityCoreVersion>2.9.2</XunitExtensibilityCoreVersion>
2222
<NSubstituteVersion>4.2.2</NSubstituteVersion>
2323
<NSubstituteAnalyzersCSharpVersion>1.0.13</NSubstituteAnalyzersCSharpVersion>
24-
<CoverletCollectorVersion>3.1.2</CoverletCollectorVersion>
24+
<CoverletCollectorVersion>6.0.2</CoverletCollectorVersion>
2525
<SeleniumWebDriverVersion>4.8.0</SeleniumWebDriverVersion>
2626
<SeleniumWebDriverChromeDriverVersion>108.0.5359.7100</SeleniumWebDriverChromeDriverVersion>
2727
<BenchmarkDotNetVersion>0.12.1</BenchmarkDotNetVersion>

tests/E2E Tests/GraphServiceClientTests/GraphServiceClientTests.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>net7.0</TargetFrameworks>
@@ -13,10 +13,6 @@
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
<PrivateAssets>all</PrivateAssets>
1515
</PackageReference>
16-
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
17-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18-
<PrivateAssets>all</PrivateAssets>
19-
</PackageReference>
2016
</ItemGroup>
2117

2218
<ItemGroup>

tests/E2E Tests/NET 7 tests/IntegrationTests/IntegrationTests.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFrameworks>net7.0</TargetFrameworks>
@@ -22,10 +22,6 @@
2222
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2323
<PrivateAssets>all</PrivateAssets>
2424
</PackageReference>
25-
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
26-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
27-
<PrivateAssets>all</PrivateAssets>
28-
</PackageReference>
2925
</ItemGroup>
3026

3127
<ItemGroup>

tests/E2E Tests/TokenAcquirerTests/TokenAcquirerTests.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>net7.0; net8.0</TargetFrameworks>
@@ -14,10 +14,6 @@
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
<PrivateAssets>all</PrivateAssets>
1616
</PackageReference>
17-
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
18-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19-
<PrivateAssets>all</PrivateAssets>
20-
</PackageReference>
2117
</ItemGroup>
2218

2319
<ItemGroup>

tests/E2E Tests/WebAppUiTests/WebAppUiTests.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>net8.0</TargetFrameworks>
@@ -19,10 +19,6 @@
1919
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2020
<PrivateAssets>all</PrivateAssets>
2121
</PackageReference>
22-
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
23-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24-
<PrivateAssets>all</PrivateAssets>
25-
</PackageReference>
2622
</ItemGroup>
2723

2824
<ItemGroup>

tests/Microsoft.Identity.Web.Test/Microsoft.Identity.Web.Test.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup Condition="'$(TargetFramework)' == 'net472'">
44
<DefineConstants>$(DefineConstants);DOTNET_472</DefineConstants>
@@ -19,6 +19,10 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22+
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
23+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
24+
<PrivateAssets>all</PrivateAssets>
25+
</PackageReference>
2226
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
2327
<PackageReference Include="Microsoft.Identity.Abstractions" Version="$(MicrosoftIdentityAbstractionsVersion)" />
2428
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNetTestSdkVersion)" />

0 commit comments

Comments
 (0)