Skip to content

Commit

Permalink
Avoid GitHub step summary file write conflicts
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 domaindrivendev#2836.
  • Loading branch information
martincostello committed May 1, 2024
1 parent 713c8e5 commit 0986ffb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@
<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" />
<ItemGroup>
<_ReportGeneratorLines Include="&lt;details&gt;&lt;summary&gt;:chart_with_upwards_trend: &lt;b&gt;$(AssemblyName) Code Coverage report&lt;/b&gt;&lt;/summary&gt;" />
<_ReportGeneratorLines Include="$([System.Environment]::NewLine)" />
</ItemGroup>
<ReadLinesFromFile File="$([System.IO.Path]::Combine($(ReportGeneratorTargetDirectory), 'SummaryGithub.md'))" >
<Output TaskParameter="Lines" ItemName="_CoverageGitHubSummary"/>
</ReadLinesFromFile>
<ItemGroup>
<_ReportGeneratorLines Include="@(_CoverageGitHubSummary)" />
<_ReportGeneratorLines Include="$([System.Environment]::NewLine)" />
<_ReportGeneratorLines Include="&lt;/details&gt;" />
</ItemGroup>
<WriteLinesToFile Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' " ContinueOnError="WarnAndContinue" File="$(GITHUB_STEP_SUMMARY)" Lines="@(_ReportGeneratorLines)" />
</Target>
</Project>

0 comments on commit 0986ffb

Please sign in to comment.