diff --git a/.github/workflows/TestSummary.ps1 b/.github/workflows/TestSummary.ps1 new file mode 100644 index 0000000..aad9b97 --- /dev/null +++ b/.github/workflows/TestSummary.ps1 @@ -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() \ No newline at end of file diff --git a/.github/workflows/Version.ps1 b/.github/workflows/Version.ps1 index b3275bb..1ed1987 100644 --- a/.github/workflows/Version.ps1 +++ b/.github/workflows/Version.ps1 @@ -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" \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c8dfbb0..209314f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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: diff --git a/Sitecore.AspNetCore.SDK.sln b/Sitecore.AspNetCore.SDK.sln index 5d2e34b..f851d2d 100644 --- a/Sitecore.AspNetCore.SDK.sln +++ b/Sitecore.AspNetCore.SDK.sln @@ -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 diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/SetupActionsProvider.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/SetupActionsProvider.cs index cfce8b0..4981810 100644 --- a/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/SetupActionsProvider.cs +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/SetupActionsProvider.cs @@ -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> GetSetupActions(Type? type, string fixtureAction) diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/StaticMethodSetupActionsProvider.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/StaticMethodSetupActionsProvider.cs index c0a3cba..7575a4c 100644 --- a/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/StaticMethodSetupActionsProvider.cs +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/StaticMethodSetupActionsProvider.cs @@ -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) diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/StaticPropertySetupActionsProvider.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/StaticPropertySetupActionsProvider.cs index 067926c..aad405f 100644 --- a/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/StaticPropertySetupActionsProvider.cs +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/ActionProviders/StaticPropertySetupActionsProvider.cs @@ -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) diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/AutoNSubstituteDataAttribute.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/AutoNSubstituteDataAttribute.cs index 0167342..6939f67 100644 --- a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/AutoNSubstituteDataAttribute.cs +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/AutoNSubstituteDataAttribute.cs @@ -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 { diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/AutoSetupDataAttribute.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/AutoSetupDataAttribute.cs index 6b3f8ca..6438916 100644 --- a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/AutoSetupDataAttribute.cs +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/AutoSetupDataAttribute.cs @@ -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 { @@ -58,7 +60,7 @@ protected AutoSetupDataAttribute( if (!fixtureSetups.Contains(DefaultFixtureSetupName)) { - fixtureSetups = new[] { DefaultFixtureSetupName }.Concat(fixtureSetups).ToArray(); + fixtureSetups = [DefaultFixtureSetupName, .. fixtureSetups]; } _fixtureSetups = fixtureSetups; diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/InlineAutoNSubstituteDataAttribute.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/InlineAutoNSubstituteDataAttribute.cs index 3ab9df3..edbd275 100644 --- a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/InlineAutoNSubstituteDataAttribute.cs +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/InlineAutoNSubstituteDataAttribute.cs @@ -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 { diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/InlineAutoSetupDataAttribute.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/InlineAutoSetupDataAttribute.cs index 628c0dc..710e0bb 100644 --- a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/InlineAutoSetupDataAttribute.cs +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/InlineAutoSetupDataAttribute.cs @@ -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) diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/MemberAutoNSubstituteDataAttribute.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/MemberAutoNSubstituteDataAttribute.cs index 1de6957..911908d 100644 --- a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/MemberAutoNSubstituteDataAttribute.cs +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/MemberAutoNSubstituteDataAttribute.cs @@ -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 { diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/MemberAutoSetupDataAttribute.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/MemberAutoSetupDataAttribute.cs index 5b9384c..718dd76 100644 --- a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/MemberAutoSetupDataAttribute.cs +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Attributes/MemberAutoSetupDataAttribute.cs @@ -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 { diff --git a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Extensions/GuardClauseAssertionExtensions.cs b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Extensions/GuardClauseAssertionExtensions.cs index 9d7df4a..139e1bc 100644 --- a/tests/Sitecore.AspNetCore.SDK.AutoFixture/Extensions/GuardClauseAssertionExtensions.cs +++ b/tests/Sitecore.AspNetCore.SDK.AutoFixture/Extensions/GuardClauseAssertionExtensions.cs @@ -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(this GuardClauseAssertion assertion) diff --git a/tests/data/Sitecore.AspNetCore.SDK.TestData/CannedResponses.cs b/tests/data/Sitecore.AspNetCore.SDK.TestData/CannedResponses.cs index a1ddc85..4740cb0 100644 --- a/tests/data/Sitecore.AspNetCore.SDK.TestData/CannedResponses.cs +++ b/tests/data/Sitecore.AspNetCore.SDK.TestData/CannedResponses.cs @@ -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; @@ -10,6 +11,7 @@ // ReSharper disable StringLiteralTypo namespace Sitecore.AspNetCore.SDK.TestData; +[ExcludeFromCodeCoverage] public static class CannedResponses { public static SitecoreLayoutResponseContent Simple => new() @@ -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}"; diff --git a/tests/data/Sitecore.AspNetCore.SDK.TestData/Models/CustomFieldType.cs b/tests/data/Sitecore.AspNetCore.SDK.TestData/Models/CustomFieldType.cs index 4d6d193..b8fb09f 100644 --- a/tests/data/Sitecore.AspNetCore.SDK.TestData/Models/CustomFieldType.cs +++ b/tests/data/Sitecore.AspNetCore.SDK.TestData/Models/CustomFieldType.cs @@ -3,6 +3,7 @@ namespace Sitecore.AspNetCore.SDK.TestData.Models; +[ExcludeFromCodeCoverage] public class CustomFieldType : Field { [SetsRequiredMembers] diff --git a/tests/data/Sitecore.AspNetCore.SDK.TestData/Serializer.cs b/tests/data/Sitecore.AspNetCore.SDK.TestData/Serializer.cs index af3b880..debe4da 100644 --- a/tests/data/Sitecore.AspNetCore.SDK.TestData/Serializer.cs +++ b/tests/data/Sitecore.AspNetCore.SDK.TestData/Serializer.cs @@ -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) diff --git a/tests/data/Sitecore.AspNetCore.SDK.TestData/TestConstants.cs b/tests/data/Sitecore.AspNetCore.SDK.TestData/TestConstants.cs index a76b12a..cd5a2ec 100644 --- a/tests/data/Sitecore.AspNetCore.SDK.TestData/TestConstants.cs +++ b/tests/data/Sitecore.AspNetCore.SDK.TestData/TestConstants.cs @@ -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";