|
16 | 16 | <ReportGeneratorReportTypes>HTML</ReportGeneratorReportTypes> |
17 | 17 | <ReportGeneratorReportTypes Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' ">$(ReportGeneratorReportTypes);MarkdownSummaryGitHub</ReportGeneratorReportTypes> |
18 | 18 | <ReportGeneratorTargetDirectory>$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage'))</ReportGeneratorTargetDirectory> |
| 19 | + <ReportGeneratorMarkdownSummary>$([System.IO.Path]::Combine($(ReportGeneratorTargetDirectory), 'SummaryGithub.md'))</ReportGeneratorMarkdownSummary> |
19 | 20 | <MergeWith>$([System.IO.Path]::Combine($(ReportGeneratorTargetDirectory), 'coverage.json'))</MergeWith> |
20 | 21 | </PropertyGroup> |
| 22 | + <UsingTask TaskName="WriteLinesToFileWithRetry" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 23 | + <ParameterGroup> |
| 24 | + <File ParameterType="System.String" Required="true" /> |
| 25 | + <Lines ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> |
| 26 | + </ParameterGroup> |
| 27 | + <Task> |
| 28 | + <Code Type="Fragment" Language="cs"><![CDATA[ |
| 29 | + var lines = new System.Collections.Generic.List<string>(); |
| 30 | + foreach (var line in Lines) |
| 31 | + { |
| 32 | + lines.Add(line.ItemSpec); |
| 33 | + } |
| 34 | + int attempt = 0; |
| 35 | + while (attempt < 3) |
| 36 | + { |
| 37 | + try |
| 38 | + { |
| 39 | + System.IO.File.AppendAllLines(File, lines); |
| 40 | + break; |
| 41 | + } |
| 42 | + catch (System.IO.IOException) |
| 43 | + { |
| 44 | + attempt++; |
| 45 | + System.Threading.Thread.Sleep(1_000); |
| 46 | + } |
| 47 | + } |
| 48 | + ]]></Code> |
| 49 | + </Task> |
| 50 | + </UsingTask> |
21 | 51 | <Target Name="GenerateCoverageReports" AfterTargets="GenerateCoverageResultAfterTest" Condition=" '$(CollectCoverage)' == 'true' "> |
22 | 52 | <ReportGenerator ReportFiles="@(CoverletReport)" ReportTypes="$(ReportGeneratorReportTypes)" Tag="$(Version)" TargetDirectory="$(ReportGeneratorTargetDirectory)" Title="$(AssemblyName)" VerbosityLevel="Warning" /> |
23 | | - <PropertyGroup Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' "> |
24 | | - <_ReportSummaryContent><details><summary>:chart_with_upwards_trend: <b>$(AssemblyName) Code Coverage report</b></summary></_ReportSummaryContent> |
| 53 | + <PropertyGroup Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' AND Exists('$(ReportGeneratorMarkdownSummary)') "> |
| 54 | + <_ReportSummaryContent><details><summary>:chart_with_upwards_trend: <b>$(AssemblyName) Code Coverage report</b> %28$(TargetFramework)%29</summary></_ReportSummaryContent> |
25 | 55 | <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent> |
26 | 56 | <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent> |
27 | | - <_ReportSummaryContent>$(_ReportSummaryContent)$([System.IO.File]::ReadAllText('$([System.IO.Path]::Combine($(ReportGeneratorTargetDirectory), 'SummaryGithub.md'))'))</_ReportSummaryContent> |
| 57 | + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.IO.File]::ReadAllText('$(ReportGeneratorMarkdownSummary)'))</_ReportSummaryContent> |
28 | 58 | <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent> |
29 | 59 | <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent> |
30 | 60 | <_ReportSummaryContent>$(_ReportSummaryContent)</details></_ReportSummaryContent> |
31 | 61 | </PropertyGroup> |
32 | | - <WriteLinesToFile Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' " ContinueOnError="WarnAndContinue" File="$(GITHUB_STEP_SUMMARY)" Lines="$(_ReportSummaryContent)" /> |
| 62 | + <WriteLinesToFileWithRetry Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' AND Exists('$(ReportGeneratorMarkdownSummary)') " ContinueOnError="WarnAndContinue" File="$(GITHUB_STEP_SUMMARY)" Lines="$(_ReportSummaryContent)" /> |
33 | 63 | </Target> |
34 | 64 | </Project> |
0 commit comments