From 819ef7b670487561635f1b829e90affd1dde921b Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 7 Mar 2025 15:27:13 +0000 Subject: [PATCH 1/2] Fix test summary reliabilty Attempt to fix write conflicts when adding the coverage to the `GITHUB_STEP_SUMMARY`. --- eng/Test.targets | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/eng/Test.targets b/eng/Test.targets index e80cc4b30b1..edd4f20c204 100644 --- a/eng/Test.targets +++ b/eng/Test.targets @@ -32,12 +32,52 @@ Cobertura;HTML $(ReportGeneratorReportTypes);MarkdownSummaryGitHub $([System.IO.Path]::Combine('$(MSBuildThisFileDirectory)', '../artifacts/', 'coverage-reports', '$(MSBuildProjectName)')) + <_MarkdownSummaryFile>$([System.IO.Path]::Combine($(ReportGeneratorTargetDirectory), 'SummaryGithub.md')) <_MarkdownSummaryPrefix><details><summary>:chart_with_upwards_trend: <b>$(AssemblyName) Code Coverage report</b> %28$(TargetFramework)%29</summary> <_MarkdownSummarySuffix></details> + + + + + + + (); + foreach (var line in Lines) + { + lines.Add(line.ItemSpec); + } + int attempt = 0; + while (attempt < 3) + { + try + { + System.IO.File.WriteAllLines(File, lines); + break; + } + catch (System.IO.IOException) + { + attempt++; + System.Threading.Thread.Sleep(1_000); + } + } + ]]> + + + - + + <_ReportSummaryContent>$(_MarkdownSummaryPrefix) + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine) + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine) + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.IO.File]::ReadAllText('$(_MarkdownSummaryFile)')) + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine) + <_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine) + <_ReportSummaryContent>$(_ReportSummaryContent)$(_MarkdownSummarySuffix) + + From 6d3d4e47c7965ddc06af677c3b1274c71715f4a5 Mon Sep 17 00:00:00 2001 From: martincostello Date: Fri, 7 Mar 2025 15:51:57 +0000 Subject: [PATCH 2/2] Fix content being overwritten Use `AppendAllLines()` not `WriteAllLines()`. --- eng/Test.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Test.targets b/eng/Test.targets index edd4f20c204..2ffbdf763ab 100644 --- a/eng/Test.targets +++ b/eng/Test.targets @@ -54,7 +54,7 @@ { try { - System.IO.File.WriteAllLines(File, lines); + System.IO.File.AppendAllLines(File, lines); break; } catch (System.IO.IOException)