-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
84 lines (84 loc) · 5.15 KB
/
Directory.Build.targets
File metadata and controls
84 lines (84 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<Project>
<PropertyGroup Condition=" '$(IsTestProject)' != 'true' AND ($(MSBuildProjectDirectory.EndsWith('Test')) OR $(MSBuildProjectDirectory.EndsWith('Tests'))) ">
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<PropertyGroup Condition=" '$(IsTestProject)' == 'true' AND '$(BuildingInsideVisualStudio)' != 'true' ">
<CollectCoverage>true</CollectCoverage>
</PropertyGroup>
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
<PackageReference Include="coverlet.msbuild" PrivateAssets="All" />
<PackageReference Include="GitHubActionsTestLogger" PrivateAssets="All" />
<PackageReference Include="JunitXml.TestLogger" PrivateAssets="All" />
<PackageReference Include="ReportGenerator" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup Condition=" '$(CollectCoverage)' == 'true' ">
<CoverletReportsPath>$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage', '$(MSBuildProjectName)'))</CoverletReportsPath>
<CoverletOutput>$([System.IO.Path]::Combine('$(CoverletReportsPath)', 'coverage'))</CoverletOutput>
<ReportGeneratorOutputMarkdown Condition=" '$(ReportGeneratorOutputMarkdown)' == '' AND '$(GITHUB_SHA)' != '' ">true</ReportGeneratorOutputMarkdown>
<ReportGeneratorReportTypes>HTML</ReportGeneratorReportTypes>
<ReportGeneratorReportTypes Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' ">$(ReportGeneratorReportTypes);MarkdownSummaryGitHub</ReportGeneratorReportTypes>
<ReportGeneratorMarkdownSummary>$([System.IO.Path]::Combine($(CoverletReportsPath), 'SummaryGithub.md'))</ReportGeneratorMarkdownSummary>
</PropertyGroup>
<UsingTask TaskName="WriteLinesToFileWithRetry" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<File ParameterType="System.String" Required="true" />
<Lines ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs"><![CDATA[
var lines = new System.Collections.Generic.List<string>();
foreach (var line in Lines)
{
lines.Add(line.ItemSpec);
}
int attempt = 0;
while (attempt < 3)
{
try
{
System.IO.File.AppendAllLines(File, lines);
break;
}
catch (System.IO.IOException)
{
attempt++;
System.Threading.Thread.Sleep(1_000);
}
}
]]></Code>
</Task>
</UsingTask>
<Target Name="GenerateCoverageReports" AfterTargets="GenerateCoverageResultAfterTest" Condition=" '$(CollectCoverage)' == 'true' ">
<ReportGenerator ReportFiles="@(CoverletReport)" ReportTypes="$(ReportGeneratorReportTypes)" Tag="$(Version)" TargetDirectory="$(CoverletReportsPath)" Title="$(AssemblyName)" VerbosityLevel="Warning" />
<PropertyGroup Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' AND Exists('$(ReportGeneratorMarkdownSummary)') ">
<_ReportSummaryContent><details><summary>:chart_with_upwards_trend: <b>$(AssemblyName) Code Coverage report</b> %28$(TargetFramework)%29</summary></_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.IO.File]::ReadAllText('$(ReportGeneratorMarkdownSummary)'))</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)</details></_ReportSummaryContent>
</PropertyGroup>
<WriteLinesToFileWithRetry Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' AND Exists('$(ReportGeneratorMarkdownSummary)') " ContinueOnError="WarnAndContinue" File="$(GITHUB_STEP_SUMMARY)" Lines="$(_ReportSummaryContent)" />
</Target>
<Target Name="SetNuGetPackageOutputs" AfterTargets="Pack" Condition=" '$(GITHUB_OUTPUT)' != '' ">
<PropertyGroup>
<_PackageNamesPath>$(ArtifactsPath)\package-names.txt</_PackageNamesPath>
</PropertyGroup>
<ReadLinesFromFile File="$(_PackageNamesPath)">
<Output TaskParameter="Lines" ItemName="_PackageNames" />
</ReadLinesFromFile>
<ItemGroup>
<_PackageNames Include="$(PackageId)" />
</ItemGroup>
<RemoveDuplicates Inputs="@(_PackageNames)">
<Output TaskParameter="Filtered" ItemName="_UniquePackageNames" />
</RemoveDuplicates>
<PropertyGroup>
<_UniquePackageNames>@(_UniquePackageNames->'%(Identity)', ',')</_UniquePackageNames>
</PropertyGroup>
<WriteLinesToFile File="$(_PackageNamesPath)" Lines="@(_UniquePackageNames)" Overwrite="true" WriteOnlyWhenDifferent="true" />
<WriteLinesToFileWithRetry File="$(GITHUB_OUTPUT)" Lines="package-names=$(_UniquePackageNames)" />
<WriteLinesToFileWithRetry File="$(GITHUB_OUTPUT)" Lines="package-version=$(Version)" />
</Target>
</Project>