|
32 | 32 | <ReportGeneratorReportTypes>Cobertura;HTML</ReportGeneratorReportTypes>
|
33 | 33 | <ReportGeneratorReportTypes Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' ">$(ReportGeneratorReportTypes);MarkdownSummaryGitHub</ReportGeneratorReportTypes>
|
34 | 34 | <ReportGeneratorTargetDirectory>$([System.IO.Path]::Combine('$(MSBuildThisFileDirectory)', '../artifacts/', 'coverage-reports', '$(MSBuildProjectName)'))</ReportGeneratorTargetDirectory>
|
| 35 | + <_MarkdownSummaryFile>$([System.IO.Path]::Combine($(ReportGeneratorTargetDirectory), 'SummaryGithub.md'))</_MarkdownSummaryFile> |
35 | 36 | <_MarkdownSummaryPrefix><details><summary>:chart_with_upwards_trend: <b>$(AssemblyName) Code Coverage report</b> %28$(TargetFramework)%29</summary></_MarkdownSummaryPrefix>
|
36 | 37 | <_MarkdownSummarySuffix></details></_MarkdownSummarySuffix>
|
37 | 38 | </PropertyGroup>
|
38 | 39 |
|
| 40 | + <UsingTask TaskName="WriteLinesToFileWithRetry" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 41 | + <ParameterGroup> |
| 42 | + <File ParameterType="System.String" Required="true" /> |
| 43 | + <Lines ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /> |
| 44 | + </ParameterGroup> |
| 45 | + <Task> |
| 46 | + <Code Type="Fragment" Language="cs"><![CDATA[ |
| 47 | + var lines = new System.Collections.Generic.List<string>(); |
| 48 | + foreach (var line in Lines) |
| 49 | + { |
| 50 | + lines.Add(line.ItemSpec); |
| 51 | + } |
| 52 | + int attempt = 0; |
| 53 | + while (attempt < 3) |
| 54 | + { |
| 55 | + try |
| 56 | + { |
| 57 | + System.IO.File.AppendAllLines(File, lines); |
| 58 | + break; |
| 59 | + } |
| 60 | + catch (System.IO.IOException) |
| 61 | + { |
| 62 | + attempt++; |
| 63 | + System.Threading.Thread.Sleep(1_000); |
| 64 | + } |
| 65 | + } |
| 66 | + ]]></Code> |
| 67 | + </Task> |
| 68 | + </UsingTask> |
| 69 | + |
39 | 70 | <Target Name="GenerateCoverageReports" AfterTargets="GenerateCoverageResultAfterTest" Condition=" '$(CollectCoverage)' == 'true' ">
|
40 | 71 | <ReportGenerator ReportFiles="@(CoverletReport)" ReportTypes="$(ReportGeneratorReportTypes)" Tag="$(TargetFramework)" TargetDirectory="$(ReportGeneratorTargetDirectory)" Title="$(AssemblyName)" VerbosityLevel="Warning" />
|
41 |
| - <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" /> |
| 72 | + <PropertyGroup Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' AND Exists('$(_MarkdownSummaryFile)') "> |
| 73 | + <_ReportSummaryContent>$(_MarkdownSummaryPrefix)</_ReportSummaryContent> |
| 74 | + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent> |
| 75 | + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent> |
| 76 | + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.IO.File]::ReadAllText('$(_MarkdownSummaryFile)'))</_ReportSummaryContent> |
| 77 | + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent> |
| 78 | + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent> |
| 79 | + <_ReportSummaryContent>$(_ReportSummaryContent)$(_MarkdownSummarySuffix)</_ReportSummaryContent> |
| 80 | + </PropertyGroup> |
| 81 | + <WriteLinesToFileWithRetry Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' AND Exists('$(_MarkdownSummaryFile)') " ContinueOnError="WarnAndContinue" File="$(GITHUB_STEP_SUMMARY)" Lines="$(_ReportSummaryContent)" /> |
42 | 82 | </Target>
|
43 | 83 | </Project>
|
0 commit comments