Skip to content

Commit

Permalink
Avoid GitHub step summary file write conflicts (#2848)
Browse files Browse the repository at this point in the history
Refactor coverage report for GitHub step summary to try and resolve file conflict issues (and make the code more readable).

Contributes to #2836.
  • Loading branch information
martincostello committed May 6, 2024
1 parent d6493dd commit eabfafa
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
13 changes: 10 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@
<ReportGeneratorReportTypes Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' ">$(ReportGeneratorReportTypes);MarkdownSummaryGitHub</ReportGeneratorReportTypes>
<ReportGeneratorTargetDirectory>$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage'))</ReportGeneratorTargetDirectory>
<MergeWith>$([System.IO.Path]::Combine($(ReportGeneratorTargetDirectory), 'coverage.json'))</MergeWith>
<_MarkdownSummaryPrefix>&lt;details&gt;&lt;summary&gt;:chart_with_upwards_trend: &lt;b&gt;$(AssemblyName) Code Coverage report&lt;/b&gt;&lt;/summary&gt;</_MarkdownSummaryPrefix>
<_MarkdownSummarySuffix>&lt;/details&gt;</_MarkdownSummarySuffix>
</PropertyGroup>
<Target Name="GenerateCoverageReports" AfterTargets="GenerateCoverageResultAfterTest" Condition=" '$(CollectCoverage)' == 'true' ">
<ReportGenerator ReportFiles="@(CoverletReport)" ReportTypes="$(ReportGeneratorReportTypes)" Tag="$(Version)" TargetDirectory="$(ReportGeneratorTargetDirectory)" Title="$(AssemblyName)" VerbosityLevel="Warning" />
<Exec Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' " Command="pwsh -Command %22('$(_MarkdownSummaryPrefix)' + [System.Environment]::NewLine + [System.Environment]::NewLine + (Get-Content $([System.IO.Path]::Combine($(ReportGeneratorTargetDirectory), 'SummaryGithub.md')) | Out-String) + [System.Environment]::NewLine + [System.Environment]::NewLine + '$(_MarkdownSummarySuffix)') >> $(GITHUB_STEP_SUMMARY)%22" />
<PropertyGroup Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' ">
<_ReportSummaryContent>&lt;details&gt;&lt;summary&gt;:chart_with_upwards_trend: &lt;b&gt;$(AssemblyName) Code Coverage report&lt;/b&gt;&lt;/summary&gt;</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.IO.File]::ReadAllText('$([System.IO.Path]::Combine($(ReportGeneratorTargetDirectory), 'SummaryGithub.md'))'))</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)&lt;/details&gt;</_ReportSummaryContent>
</PropertyGroup>
<WriteLinesToFile Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' " ContinueOnError="WarnAndContinue" File="$(GITHUB_STEP_SUMMARY)" Lines="$(_ReportSummaryContent)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Swashbuckle.AspNetCore.IntegrationTests
{
[Collection("TestSite")]
public class CustomDocumentSerializerTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Swashbuckle.AspNetCore.IntegrationTests
{
[Collection("TestSite")]
public class DocumentProviderTests
{
[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Swashbuckle.AspNetCore.IntegrationTests
{
[Collection("TestSite")]
public class ReDocIntegrationTests
{
[Fact]
Expand Down Expand Up @@ -58,4 +59,4 @@ public async Task RedocMiddleware_CanBeConfiguredMultipleTimes(string redocUrl,
Assert.Contains(swaggerPath, content);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Swashbuckle.AspNetCore.IntegrationTests
{
[Collection("TestSite")]
public class SwaggerIntegrationTests
{
[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Swashbuckle.AspNetCore.IntegrationTests
{
[Collection("TestSite")]
public class SwaggerUIIntegrationTests
{
[Theory]
Expand Down Expand Up @@ -88,4 +89,4 @@ public async Task SwaggerUIMiddleware_CanBeConfiguredMultipleTimes(string swagge
}
}
}
}
}

0 comments on commit eabfafa

Please sign in to comment.