Skip to content

Commit 0a75858

Browse files
committed
Improved Build Summary
+ Excluded and filtered test code
1 parent b6387b9 commit 0a75858

18 files changed

+134
-21
lines changed

.github/workflows/TestSummary.ps1

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[CmdletBinding()]
2+
Param (
3+
[Parameter(HelpMessage = "Path to the XML summary file of code coverage.")]
4+
[string]$CoverageReportPath,
5+
[Parameter(HelpMessage = "Path to the folder with TRX results.")]
6+
[string]$ResultFolderPath
7+
)
8+
9+
$result = [System.Text.StringBuilder]::new()
10+
11+
# Test Result Summary
12+
[void]$result.AppendLine("# :vertical_traffic_light: Test Results")
13+
[void]$result.AppendLine("| Assembly | :arrow_forward: | :white_check_mark: | :x: | :hash: |")
14+
[void]$result.AppendLine("|----------|-----------------|--------------------|-----|--------|")
15+
$totalExecuted = 0
16+
$totalPassed = 0
17+
$totalFailed = 0
18+
$total = 0
19+
foreach ($trx in (Get-ChildItem $ResultFolderPath -Include *.trx)) {
20+
$testrun = ([xml](Get-Content ([string]$trx).Replace("[", "``[").Replace("]", "``]"))).TestRun
21+
$counters = $testrun.ResultSummary.Counters
22+
if ($counters.Total -gt 0) {
23+
$assembly = $testrun.TestDefinitions.ChildNodes[0].TestMethod.CodeBase.Split("/")[-1].Replace(".dll", "")
24+
[void]$result.Append("| $assembly ")
25+
[void]$result.Append("| $($counters.Executed) ")
26+
$totalExecuted = $totalExecuted + $counters.Executed
27+
[void]$result.Append("| $($counters.Passed) ")
28+
$totalPassed = $totalPassed + $counters.Passed
29+
[void]$result.Append("| $($counters.Failed) ")
30+
$totalFailed = $totalFailed + $counters.Failed
31+
[void]$result.Append("| $($counters.Total) ")
32+
$total = $total + $counters.Total
33+
[void]$result.AppendLine("|")
34+
}
35+
}
36+
[void]$result.AppendLine("| Total | $totalExecuted | $totalPassed | $totalFailed | $total |")
37+
38+
# Coverage Report Summary
39+
$report = ([xml](Get-Content $CoverageReportPath)).CoverageReport
40+
$summary = $report.Summary
41+
[void]$result.AppendLine("# :bar_chart: Code Coverage")
42+
43+
[void]$result.AppendLine("## Summary")
44+
[void]$result.AppendLine("| Lines | Branches | Methods |")
45+
[void]$result.AppendLine("|-------|----------|---------|")
46+
[void]$result.Append("| $($summary.Linecoverage)% ($($summary.Coveredlines) / $($summary.Coverablelines)) ")
47+
[void]$result.Append("| $($summary.Branchcoverage)% ($($summary.Coveredbranches) / $($summary.Totalbranches)) ")
48+
[void]$result.Append("| $($summary.Methodcoverage)% ($($summary.Coveredmethods) / $($summary.Totalmethods)) ")
49+
[void]$result.AppendLine("|")
50+
51+
[void]$result.AppendLine("## Assembly Details")
52+
[void]$result.AppendLine("| Assembly | Lines | Branches | Methods |")
53+
[void]$result.AppendLine("|----------|-------|----------|---------|")
54+
foreach ($assembly in $report.Coverage.ChildNodes) {
55+
[void]$result.Append("| $($assembly.name) ")
56+
[void]$result.Append("| $($assembly.coverage)% ($($assembly.coveredlines) / $($assembly.coverablelines)) ")
57+
[void]$result.Append("| $($assembly.branchcoverage)% ($($assembly.coveredbranches) / $($assembly.totalbranches)) ")
58+
[void]$result.Append("| $($assembly.methodcoverage)% ($($assembly.coveredmethods) / $($assembly.totalmethods)) ")
59+
[void]$result.AppendLine("|")
60+
}
61+
62+
return $result.ToString()

.github/workflows/Version.ps1

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,21 @@ function Set-Version
6969
if (![string]::IsNullOrEmpty($Suffix)) {
7070
$suffixElement = $xml.CreateElement("VersionSuffix")
7171
$suffixElement.InnerText = $Suffix
72-
$properties.AppendChild($suffixElement)
72+
[void]$properties.AppendChild($suffixElement)
7373
}
7474

75-
$properties.AppendChild($assemblyVersionElement)
76-
$properties.AppendChild($versionElement)
77-
$properties.AppendChild($fileVersionElement)
75+
[void]$properties.AppendChild($assemblyVersionElement)
76+
[void]$properties.AppendChild($versionElement)
77+
[void]$properties.AppendChild($fileVersionElement)
7878

79-
$xml.Save($Path)
79+
[void]$xml.Save($Path)
8080
}
8181

8282
$newVersion = Get-Version $PreviousVersion $Message
8383
$suffix = Get-VersionSuffix
84-
Set-Version $Path $newVersion $suffix | Out-Null
84+
Set-Version $Path $newVersion $suffix
85+
86+
"# :arrow_up_small: Version" >> $Env:GITHUB_STEP_SUMMARY
87+
$newVersion >> $Env:GITHUB_STEP_SUMMARY
8588

8689
return "newVersion=$newVersion"

.github/workflows/build.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,17 @@ jobs:
8585
run: dotnet build -c ${{ inputs.buildConfiguration }} --no-restore
8686

8787
- name: Test
88-
run: dotnet test -c ${{ inputs.buildConfiguration }} --no-build --verbosity normal --logger trx --collect:"XPlat Code Coverage" --results-directory TestResults
88+
run: dotnet test -c ${{ inputs.buildConfiguration }} --no-build --verbosity normal --logger trx --collect:"XPlat Code Coverage" --results-directory TestResults -p:Exclude=\"[Sitecore.AspNetCore.SDK.AutoFixture]*,[Sitecore.AspNetCore.SDK.TestData]*\"
89+
90+
- name: Code Coverage Report
91+
run: |
92+
dotnet tool install -g dotnet-reportgenerator-globaltool
93+
reportgenerator -reports:"TestResults/**/*.xml" -targetdir:"TestResults/Report" -reporttypes:Html -assemblyfilters:"-Sitecore.AspNetCore.SDK.AutoFixture;-Sitecore.AspNetCore.SDK.TestData"
94+
reportgenerator -reports:"TestResults/**/*.xml" -targetdir:"TestResults/Summary" -reporttypes:XmlSummary -assemblyfilters:"-Sitecore.AspNetCore.SDK.AutoFixture;-Sitecore.AspNetCore.SDK.TestData"
95+
96+
- name: Test Summary
97+
shell: pwsh
98+
run: ./.github/workflows/TestSummary.ps1 -CoverageReportPath "./TestResults/Summary/Summary.xml" -ResultFolderPath "./TestResults/*" >> $Env:GITHUB_STEP_SUMMARY
8999

90100
- name: Upload dotnet test results
91101
uses: actions/upload-artifact@v4
@@ -98,6 +108,13 @@ jobs:
98108
working-directory: ./tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks
99109
run: dotnet run -c Release
100110

111+
- name: Benchmark Summary
112+
working-directory: ./tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/BenchmarkDotNet.Artifacts/results
113+
shell: pwsh
114+
run: |
115+
"# :rocket: Benchmarks" >> $Env:GITHUB_STEP_SUMMARY
116+
Get-Content -Path .\* -Filter *.md >> $Env:GITHUB_STEP_SUMMARY
117+
101118
- name: Upload benchmark results
102119
uses: actions/upload-artifact@v4
103120
with:

Sitecore.AspNetCore.SDK.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
9797
.github\workflows\build.yml = .github\workflows\build.yml
9898
.github\workflows\main.yml = .github\workflows\main.yml
9999
.github\workflows\pullrequest.yml = .github\workflows\pullrequest.yml
100+
.github\workflows\TestSummary.ps1 = .github\workflows\TestSummary.ps1
100101
.github\workflows\Version.ps1 = .github\workflows\Version.ps1
101102
EndProjectSection
102103
EndProject

tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/SetupActionsProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using AutoFixture;
1+
using System.Diagnostics.CodeAnalysis;
2+
using AutoFixture;
23

34
namespace Sitecore.AspNetCore.SDK.AutoFixture.ActionProviders;
45

6+
[ExcludeFromCodeCoverage]
57
public abstract class SetupActionsProvider : ISetupActionsProvider
68
{
79
public virtual IEnumerable<Action<IFixture>> GetSetupActions(Type? type, string fixtureAction)

tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/StaticMethodSetupActionsProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System.Reflection;
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Reflection;
23

34
namespace Sitecore.AspNetCore.SDK.AutoFixture.ActionProviders;
45

6+
[ExcludeFromCodeCoverage]
57
public class StaticMethodSetupActionsProvider : SetupActionsProvider
68
{
79
protected override object? ResolveFromType(Type? type, string fixtureAction)

tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/StaticPropertySetupActionsProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System.Reflection;
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Reflection;
23

34
namespace Sitecore.AspNetCore.SDK.AutoFixture.ActionProviders;
45

6+
[ExcludeFromCodeCoverage]
57
public class StaticPropertySetupActionsProvider : SetupActionsProvider
68
{
79
protected override object? ResolveFromType(Type? type, string fixtureAction)

tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/AutoNSubstituteDataAttribute.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
using AutoFixture;
1+
using System.Diagnostics.CodeAnalysis;
2+
using AutoFixture;
23
using AutoFixture.AutoNSubstitute;
34

45
namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;
56

7+
[ExcludeFromCodeCoverage]
68
[AttributeUsage(AttributeTargets.Method)]
79
public class AutoNSubstituteDataAttribute : AutoSetupDataAttribute
810
{

tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/AutoSetupDataAttribute.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using System.Reflection;
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Reflection;
23
using AutoFixture;
34
using AutoFixture.Xunit2;
45
using Sitecore.AspNetCore.SDK.AutoFixture.ActionProviders;
56

67
namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;
78

9+
[ExcludeFromCodeCoverage]
810
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
911
public class AutoSetupDataAttribute : AutoDataAttribute
1012
{
@@ -58,7 +60,7 @@ protected AutoSetupDataAttribute(
5860

5961
if (!fixtureSetups.Contains(DefaultFixtureSetupName))
6062
{
61-
fixtureSetups = new[] { DefaultFixtureSetupName }.Concat(fixtureSetups).ToArray();
63+
fixtureSetups = [DefaultFixtureSetupName, .. fixtureSetups];
6264
}
6365

6466
_fixtureSetups = fixtureSetups;

tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/InlineAutoNSubstituteDataAttribute.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;
1+
using System.Diagnostics.CodeAnalysis;
22

3+
namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;
4+
5+
[ExcludeFromCodeCoverage]
36
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
47
public class InlineAutoNSubstituteDataAttribute : InlineAutoSetupDataAttribute
58
{

0 commit comments

Comments
 (0)