Skip to content

Commit

Permalink
Improved Build Summary (#7)
Browse files Browse the repository at this point in the history
<!-- Provide a general summary of your changes in the Title above -->
<!-- Apply the label "bug" or "enhacement" as applicable. -->

## Description / Motivation
<!-- Describe your changes in detail -->
<!-- Why is this change required? What problem does it solve? -->
<!-- If it fixes an open issue, please link to the issue here. -->
This adds a nice build summary to inspect results of testing, code
coverage and benchmark runs. To clean up the results certain test code
has been filtered and excluded.

## Testing

- [X] The Unit & Intergration tests are passing.
- [X] I have added the necesary tests to cover my changes.

## Terms
<!-- Place an X in the [] to check. -->

<!-- The Code of Conduct helps create a safe space for everyone. We
require that everyone agrees to it. -->
- [X] I agree to follow this project's [Code of
Conduct](CODE_OF_CONDUCT.md).

Co-authored-by: Ivan Lieckens <[email protected]>
  • Loading branch information
sc-ivanlieckens and IvanLieckens authored Aug 9, 2024
1 parent 4967f4b commit 0ce00e4
Show file tree
Hide file tree
Showing 18 changed files with 134 additions and 21 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/TestSummary.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[CmdletBinding()]
Param (
[Parameter(HelpMessage = "Path to the XML summary file of code coverage.")]
[string]$CoverageReportPath,
[Parameter(HelpMessage = "Path to the folder with TRX results.")]
[string]$ResultFolderPath
)

$result = [System.Text.StringBuilder]::new()

# Test Result Summary
[void]$result.AppendLine("# :vertical_traffic_light: Test Results")
[void]$result.AppendLine("| Assembly | :arrow_forward: | :white_check_mark: | :x: | :hash: |")
[void]$result.AppendLine("|----------|-----------------|--------------------|-----|--------|")
$totalExecuted = 0
$totalPassed = 0
$totalFailed = 0
$total = 0
foreach ($trx in (Get-ChildItem $ResultFolderPath -Include *.trx)) {
$testrun = ([xml](Get-Content ([string]$trx).Replace("[", "``[").Replace("]", "``]"))).TestRun
$counters = $testrun.ResultSummary.Counters
if ($counters.Total -gt 0) {
$assembly = $testrun.TestDefinitions.ChildNodes[0].TestMethod.CodeBase.Split("/")[-1].Replace(".dll", "")
[void]$result.Append("| $assembly ")
[void]$result.Append("| $($counters.Executed) ")
$totalExecuted = $totalExecuted + $counters.Executed
[void]$result.Append("| $($counters.Passed) ")
$totalPassed = $totalPassed + $counters.Passed
[void]$result.Append("| $($counters.Failed) ")
$totalFailed = $totalFailed + $counters.Failed
[void]$result.Append("| $($counters.Total) ")
$total = $total + $counters.Total
[void]$result.AppendLine("|")
}
}
[void]$result.AppendLine("| Total | $totalExecuted | $totalPassed | $totalFailed | $total |")

# Coverage Report Summary
$report = ([xml](Get-Content $CoverageReportPath)).CoverageReport
$summary = $report.Summary
[void]$result.AppendLine("# :bar_chart: Code Coverage")

[void]$result.AppendLine("## Summary")
[void]$result.AppendLine("| Lines | Branches | Methods |")
[void]$result.AppendLine("|-------|----------|---------|")
[void]$result.Append("| $($summary.Linecoverage)% ($($summary.Coveredlines) / $($summary.Coverablelines)) ")
[void]$result.Append("| $($summary.Branchcoverage)% ($($summary.Coveredbranches) / $($summary.Totalbranches)) ")
[void]$result.Append("| $($summary.Methodcoverage)% ($($summary.Coveredmethods) / $($summary.Totalmethods)) ")
[void]$result.AppendLine("|")

[void]$result.AppendLine("## Assembly Details")
[void]$result.AppendLine("| Assembly | Lines | Branches | Methods |")
[void]$result.AppendLine("|----------|-------|----------|---------|")
foreach ($assembly in $report.Coverage.ChildNodes) {
[void]$result.Append("| $($assembly.name) ")
[void]$result.Append("| $($assembly.coverage)% ($($assembly.coveredlines) / $($assembly.coverablelines)) ")
[void]$result.Append("| $($assembly.branchcoverage)% ($($assembly.coveredbranches) / $($assembly.totalbranches)) ")
[void]$result.Append("| $($assembly.methodcoverage)% ($($assembly.coveredmethods) / $($assembly.totalmethods)) ")
[void]$result.AppendLine("|")
}

return $result.ToString()
15 changes: 9 additions & 6 deletions .github/workflows/Version.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,21 @@ function Set-Version
if (![string]::IsNullOrEmpty($Suffix)) {
$suffixElement = $xml.CreateElement("VersionSuffix")
$suffixElement.InnerText = $Suffix
$properties.AppendChild($suffixElement)
[void]$properties.AppendChild($suffixElement)
}

$properties.AppendChild($assemblyVersionElement)
$properties.AppendChild($versionElement)
$properties.AppendChild($fileVersionElement)
[void]$properties.AppendChild($assemblyVersionElement)
[void]$properties.AppendChild($versionElement)
[void]$properties.AppendChild($fileVersionElement)

$xml.Save($Path)
[void]$xml.Save($Path)
}

$newVersion = Get-Version $PreviousVersion $Message
$suffix = Get-VersionSuffix
Set-Version $Path $newVersion $suffix | Out-Null
Set-Version $Path $newVersion $suffix

"# :arrow_up_small: Version" >> $Env:GITHUB_STEP_SUMMARY
$newVersion >> $Env:GITHUB_STEP_SUMMARY

return "newVersion=$newVersion"
19 changes: 18 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,17 @@ jobs:
run: dotnet build -c ${{ inputs.buildConfiguration }} --no-restore

- name: Test
run: dotnet test -c ${{ inputs.buildConfiguration }} --no-build --verbosity normal --logger trx --collect:"XPlat Code Coverage" --results-directory TestResults
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]*\"

- name: Code Coverage Report
run: |
dotnet tool install -g dotnet-reportgenerator-globaltool
reportgenerator -reports:"TestResults/**/*.xml" -targetdir:"TestResults/Report" -reporttypes:Html -assemblyfilters:"-Sitecore.AspNetCore.SDK.AutoFixture;-Sitecore.AspNetCore.SDK.TestData"
reportgenerator -reports:"TestResults/**/*.xml" -targetdir:"TestResults/Summary" -reporttypes:XmlSummary -assemblyfilters:"-Sitecore.AspNetCore.SDK.AutoFixture;-Sitecore.AspNetCore.SDK.TestData"
- name: Test Summary
shell: pwsh
run: ./.github/workflows/TestSummary.ps1 -CoverageReportPath "./TestResults/Summary/Summary.xml" -ResultFolderPath "./TestResults/*" >> $Env:GITHUB_STEP_SUMMARY

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

- name: Benchmark Summary
working-directory: ./tests/Sitecore.AspNetCore.SDK.RenderingEngine.Benchmarks/BenchmarkDotNet.Artifacts/results
shell: pwsh
run: |
"# :rocket: Benchmarks" >> $Env:GITHUB_STEP_SUMMARY
Get-Content -Path .\* -Filter *.md >> $Env:GITHUB_STEP_SUMMARY
- name: Upload benchmark results
uses: actions/upload-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions Sitecore.AspNetCore.SDK.sln
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\build.yml = .github\workflows\build.yml
.github\workflows\main.yml = .github\workflows\main.yml
.github\workflows\pullrequest.yml = .github\workflows\pullrequest.yml
.github\workflows\TestSummary.ps1 = .github\workflows\TestSummary.ps1
.github\workflows\Version.ps1 = .github\workflows\Version.ps1
EndProjectSection
EndProject
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using AutoFixture;
using System.Diagnostics.CodeAnalysis;
using AutoFixture;

namespace Sitecore.AspNetCore.SDK.AutoFixture.ActionProviders;

[ExcludeFromCodeCoverage]
public abstract class SetupActionsProvider : ISetupActionsProvider
{
public virtual IEnumerable<Action<IFixture>> GetSetupActions(Type? type, string fixtureAction)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace Sitecore.AspNetCore.SDK.AutoFixture.ActionProviders;

[ExcludeFromCodeCoverage]
public class StaticMethodSetupActionsProvider : SetupActionsProvider
{
protected override object? ResolveFromType(Type? type, string fixtureAction)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

namespace Sitecore.AspNetCore.SDK.AutoFixture.ActionProviders;

[ExcludeFromCodeCoverage]
public class StaticPropertySetupActionsProvider : SetupActionsProvider
{
protected override object? ResolveFromType(Type? type, string fixtureAction)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using AutoFixture;
using System.Diagnostics.CodeAnalysis;
using AutoFixture;
using AutoFixture.AutoNSubstitute;

namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;

[ExcludeFromCodeCoverage]
[AttributeUsage(AttributeTargets.Method)]
public class AutoNSubstituteDataAttribute : AutoSetupDataAttribute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using AutoFixture;
using AutoFixture.Xunit2;
using Sitecore.AspNetCore.SDK.AutoFixture.ActionProviders;

namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;

[ExcludeFromCodeCoverage]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property)]
public class AutoSetupDataAttribute : AutoDataAttribute
{
Expand Down Expand Up @@ -58,7 +60,7 @@ protected AutoSetupDataAttribute(

if (!fixtureSetups.Contains(DefaultFixtureSetupName))
{
fixtureSetups = new[] { DefaultFixtureSetupName }.Concat(fixtureSetups).ToArray();
fixtureSetups = [DefaultFixtureSetupName, .. fixtureSetups];
}

_fixtureSetups = fixtureSetups;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;
using System.Diagnostics.CodeAnalysis;

namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;

[ExcludeFromCodeCoverage]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class InlineAutoNSubstituteDataAttribute : InlineAutoSetupDataAttribute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using AutoFixture.Xunit2;
using System.Diagnostics.CodeAnalysis;
using AutoFixture.Xunit2;

namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;

[ExcludeFromCodeCoverage]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class InlineAutoSetupDataAttribute(AutoDataAttribute baseAttribute, params object[] values)
: InlineAutoDataAttribute(baseAttribute, values)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;
using System.Diagnostics.CodeAnalysis;

namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;

[ExcludeFromCodeCoverage]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class MemberAutoNSubstituteDataAttribute : MemberAutoSetupDataAttribute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using Xunit;

namespace Sitecore.AspNetCore.SDK.AutoFixture.Attributes;

[ExcludeFromCodeCoverage]
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public class MemberAutoSetupDataAttribute : MemberDataAttributeBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using AutoFixture.Idioms;

namespace Sitecore.AspNetCore.SDK.AutoFixture.Extensions;

[ExcludeFromCodeCoverage]
public static class GuardClauseAssertionExtensions
{
public static void Verify<T>(this GuardClauseAssertion assertion)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text.Encodings.Web;
using Sitecore.AspNetCore.SDK.LayoutService.Client.Response;
using Sitecore.AspNetCore.SDK.LayoutService.Client.Response.Model;
Expand All @@ -10,6 +11,7 @@
// ReSharper disable StringLiteralTypo
namespace Sitecore.AspNetCore.SDK.TestData;

[ExcludeFromCodeCoverage]
public static class CannedResponses
{
public static SitecoreLayoutResponseContent Simple => new()
Expand Down Expand Up @@ -3913,6 +3915,7 @@ public static class CannedResponses
};

// ReSharper disable once MemberCanBePrivate.Global - Must be available
[ExcludeFromCodeCoverage]
public static class SitecoreLayoutIds
{
public const string Styleguide1LayoutId = "{E02DDB9B-A062-5E50-924A-1940D7E053C1}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Sitecore.AspNetCore.SDK.TestData.Models;

[ExcludeFromCodeCoverage]
public class CustomFieldType : Field<string>
{
[SetsRequiredMembers]
Expand Down
4 changes: 3 additions & 1 deletion tests/data/Sitecore.AspNetCore.SDK.TestData/Serializer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Text;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Text.Json;
using Sitecore.AspNetCore.SDK.LayoutService.Client.Serialization;

namespace Sitecore.AspNetCore.SDK.TestData;

[ExcludeFromCodeCoverage]
public static class Serializer
{
public static string Serialize(object obj)
Expand Down
4 changes: 3 additions & 1 deletion tests/data/Sitecore.AspNetCore.SDK.TestData/TestConstants.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Globalization;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace Sitecore.AspNetCore.SDK.TestData;

[ExcludeFromCodeCoverage]
public static class TestConstants
{
public const string TestFieldValue = "This is a test";
Expand Down

0 comments on commit 0ce00e4

Please sign in to comment.