Skip to content

Commit 350f56f

Browse files
committed
(build) update to cake-build 3.0.0
1 parent 98f7217 commit 350f56f

17 files changed

+239
-31
lines changed

build/Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
<Using Include="Common.Utilities.Constants" Alias="Constants"/>
3939
</ItemGroup>
4040
<ItemGroup>
41-
<PackageReference Include="Cake.Common" />
4241
<PackageReference Include="Cake.Compression" />
4342
<PackageReference Include="Cake.Frosting" />
4443
<PackageReference Include="Cake.Incubator" />

build/Directory.Packages.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
55
<ItemGroup>
6-
<PackageVersion Include="Cake.Common" Version="2.3.0" />
76
<PackageVersion Include="Cake.Compression" Version="0.3.0" />
87
<PackageVersion Include="Cake.Codecov" Version="1.0.1" />
98
<PackageVersion Include="Cake.Coverlet" Version="2.5.4" />
10-
<PackageVersion Include="Cake.Frosting" Version="2.3.0" />
9+
<PackageVersion Include="Cake.Frosting" Version="3.0.0" />
1110
<PackageVersion Include="Cake.Incubator" Version="7.0.0" />
1211
<PackageVersion Include="Cake.DotNetLocalTools.Module" Version="1.0.2" />
1312
<PackageVersion Include="Cake.Docker" Version="1.1.2" />

build/artifacts/BuildLifetime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ namespace Artifacts;
44

55
public class BuildLifetime : BuildLifetimeBase<BuildContext>
66
{
7-
public override void Setup(BuildContext context)
7+
public override void Setup(BuildContext context, ISetupContext info)
88
{
9-
base.Setup(context);
9+
base.Setup(context, info);
1010

1111
context.IsDockerOnLinux = context.DockerCustomCommand("info --format '{{.OSType}}'").First().Replace("'", string.Empty) == "linux";
1212

build/build/BuildLifetime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ namespace Build;
55

66
public class BuildLifetime : BuildLifetimeBase<BuildContext>
77
{
8-
public override void Setup(BuildContext context)
8+
public override void Setup(BuildContext context, ISetupContext info)
99
{
10-
base.Setup(context);
10+
base.Setup(context, info);
1111

1212
context.MsBuildConfiguration = context.Argument(Arguments.Configuration, "Release");
1313
context.EnabledUnitTests = context.IsEnabled(EnvVars.EnabledUnitTests);

build/build/Tasks/Test/UnitTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Cake.Coverlet;
44
using Cake.Incubator.LoggingExtensions;
55
using Common.Utilities;
6+
using CoverletSettings = Common.Addins.Cake.Coverlet.CoverletSettings;
67

78
namespace Build.Tasks;
89

build/chores/BuildLifetime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Chores;
44

55
public class BuildLifetime : FrostingLifetime<BuildContext>
66
{
7-
public override void Setup(BuildContext context)
7+
public override void Setup(BuildContext context, ISetupContext info)
88
{
99
context.StartGroup("Build Setup");
1010
context.EndGroup();

build/common/Addins/Cake.Coverlet/ArgumentsProcessor.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ namespace Common.Addins.Cake.Coverlet;
44

55
internal static class ArgumentsProcessor
66
{
7-
public static ProcessArgumentBuilder ProcessMSBuildArguments(
7+
public static ProcessArgumentBuilder ProcessMsBuildArguments(
88
CoverletSettings settings,
99
ICakeEnvironment cakeEnvironment,
1010
ProcessArgumentBuilder builder,
1111
FilePath project)
1212
{
13-
builder.AppendMSBuildProperty(nameof(CoverletSettings.CollectCoverage), settings.CollectCoverage.ToString());
13+
builder.AppendMsBuildProperty(nameof(CoverletSettings.CollectCoverage), settings.CollectCoverage.ToString());
1414
builder.AppendPropertyList(nameof(CoverletSettings.CoverletOutputFormat), SplitFlagEnum(settings.CoverletOutputFormat));
1515

1616
if (settings.Threshold.HasValue)
@@ -20,7 +20,7 @@ public static ProcessArgumentBuilder ProcessMSBuildArguments(
2020
throw new Exception("Threshold Percentage cannot be set as greater than 100%");
2121
}
2222

23-
builder.AppendMSBuildProperty(nameof(CoverletSettings.Threshold), settings.Threshold.ToString()!);
23+
builder.AppendMsBuildProperty(nameof(CoverletSettings.Threshold), settings.Threshold.ToString()!);
2424

2525
if (settings.ThresholdType != ThresholdType.NotSet)
2626
{
@@ -33,7 +33,7 @@ public static ProcessArgumentBuilder ProcessMSBuildArguments(
3333
var directoryPath = settings.CoverletOutputDirectory
3434
.MakeAbsolute(cakeEnvironment).FullPath;
3535

36-
builder.AppendMSBuildPropertyQuoted("CoverletOutput", directoryPath);
36+
builder.AppendMsBuildPropertyQuoted("CoverletOutput", directoryPath);
3737
}
3838
else if (!string.IsNullOrEmpty(settings.CoverletOutputName))
3939
{
@@ -42,7 +42,7 @@ public static ProcessArgumentBuilder ProcessMSBuildArguments(
4242

4343
var filepath = FilePath.FromString(settings.OutputTransformer(settings.CoverletOutputName, directoryPath));
4444

45-
builder.AppendMSBuildPropertyQuoted("CoverletOutput", filepath.MakeAbsolute(cakeEnvironment).FullPath);
45+
builder.AppendMsBuildPropertyQuoted("CoverletOutput", filepath.MakeAbsolute(cakeEnvironment).FullPath);
4646
}
4747

4848
if (settings.ExcludeByFile.Count > 0)
@@ -69,12 +69,12 @@ public static ProcessArgumentBuilder ProcessMSBuildArguments(
6969

7070
if (settings.MergeWithFile != null && settings.MergeWithFile.GetExtension() == ".json")
7171
{
72-
builder.AppendMSBuildPropertyQuoted("MergeWith", settings.MergeWithFile.MakeAbsolute(cakeEnvironment).FullPath);
72+
builder.AppendMsBuildPropertyQuoted("MergeWith", settings.MergeWithFile.MakeAbsolute(cakeEnvironment).FullPath);
7373
}
7474

7575
if (settings.IncludeTestAssembly.HasValue)
7676
{
77-
builder.AppendMSBuildProperty(nameof(CoverletSettings.IncludeTestAssembly), settings.IncludeTestAssembly.Value ? bool.TrueString : bool.FalseString);
77+
builder.AppendMsBuildProperty(nameof(CoverletSettings.IncludeTestAssembly), settings.IncludeTestAssembly.Value ? bool.TrueString : bool.FalseString);
7878
}
7979

8080
return builder;

build/common/Addins/Cake.Coverlet/BuilderExtension.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ namespace Common.Addins.Cake.Coverlet;
22

33
internal static class BuilderExtension
44
{
5-
internal static ProcessArgumentBuilder AppendMSBuildProperty(this ProcessArgumentBuilder builder, string propertyName, string value)
5+
internal static ProcessArgumentBuilder AppendMsBuildProperty(this ProcessArgumentBuilder builder, string propertyName, string value)
66
{
77
builder.AppendSwitch($"/property:{propertyName}", "=", value);
88
return builder;
99
}
1010

11-
internal static ProcessArgumentBuilder AppendMSBuildPropertyQuoted(this ProcessArgumentBuilder builder, string propertyName, string value)
11+
internal static ProcessArgumentBuilder AppendMsBuildPropertyQuoted(this ProcessArgumentBuilder builder, string propertyName, string value)
1212
{
1313
builder.AppendSwitchQuoted($"/property:{propertyName}", "=", value);
1414
return builder;
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
#nullable disable
2+
using Cake.Coverlet;
3+
4+
namespace Common.Addins.Cake.Coverlet;
5+
6+
/// <summary>
7+
/// A delegate representing the output transformation
8+
/// </summary>
9+
/// <param name="fileName">The file name</param>
10+
/// <param name="directoryPath">The directory path</param>
11+
/// <returns>The path and name of the file (without extension)</returns>
12+
public delegate string OutputTransformer(string fileName, string directoryPath);
13+
14+
/// <summary>
15+
/// Settings used by Cake.Coverlet
16+
/// </summary>
17+
public class CoverletSettings : DotNetSettings
18+
{
19+
/// <summary>
20+
/// Gets or sets if coverage should be collected
21+
/// </summary>
22+
public bool CollectCoverage { get; set; }
23+
24+
/// <summary>
25+
/// Gets or sets the output format for Coverlet
26+
/// </summary>
27+
public CoverletOutputFormat CoverletOutputFormat { get; set; } = CoverletOutputFormat.json;
28+
29+
/// <summary>
30+
/// Gets or sets the threshold for Coverlet to use in percent
31+
/// </summary>
32+
public uint? Threshold { get; set; }
33+
34+
/// <summary>
35+
/// Gets or sets the type of threshold to apply.
36+
/// </summary>
37+
/// <remarks>
38+
/// This has no effect if Threshold is not set to a value
39+
/// </remarks>
40+
public ThresholdType ThresholdType { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the output directory the output files
44+
/// </summary>
45+
public DirectoryPath CoverletOutputDirectory { get; set; }
46+
47+
/// <summary>
48+
/// Gets or sets the name of the output file excluding format
49+
/// </summary>
50+
public string CoverletOutputName { get; set; }
51+
52+
/// <summary>
53+
/// Gets or sets the list of files to exclude
54+
/// </summary>
55+
public List<string> ExcludeByFile { get; set; } = new();
56+
57+
/// <summary>
58+
/// Gets or sets the list of files to exclude
59+
/// </summary>
60+
public List<string> ExcludeByAttribute { get; set; } = new();
61+
62+
/// <summary>
63+
/// Gets or sets the exclusion filters
64+
/// </summary>
65+
public List<string> Exclude { get; set; } = new();
66+
67+
/// <summary>
68+
/// Gets or sets a inclusion filters
69+
/// </summary>
70+
public List<string> Include { get; set; } = new();
71+
72+
/// <summary>
73+
/// Gets or sets if the test assembly should be included
74+
/// </summary>
75+
public bool? IncludeTestAssembly { get; set; }
76+
77+
/// <summary>
78+
/// Gets or sets the file to merge the results of the run with
79+
/// </summary>
80+
public FilePath MergeWithFile { get; set; }
81+
82+
/// <summary>
83+
/// Gets or sets a transformation function taking the <see cref="CoverletOutputName"/> and
84+
/// returning the new file name without an extension
85+
/// </summary>
86+
public OutputTransformer OutputTransformer { get; set; }
87+
= (fileName, dir) => $@"{dir}\{fileName}";
88+
89+
/// <summary>
90+
/// Adds a filter to the list of exclusions
91+
/// </summary>
92+
/// <param name="filter">The filter to add</param>
93+
/// <returns></returns>
94+
public CoverletSettings WithFilter(string filter)
95+
{
96+
Exclude.Add(filter);
97+
return this;
98+
}
99+
100+
/// <summary>
101+
/// Adds a file to the list of files to exclude
102+
/// </summary>
103+
/// <param name="file">The file to exclude</param>
104+
/// <returns></returns>
105+
public CoverletSettings WithFileExclusion(string file)
106+
{
107+
ExcludeByFile.Add(file);
108+
return this;
109+
}
110+
111+
/// <summary>
112+
/// Adds a attribute to the list of attribute to exclude
113+
/// </summary>
114+
/// <param name="attribute">The attribute to exclude</param>
115+
/// <returns></returns>
116+
public CoverletSettings WithAttributeExclusion(string attribute)
117+
{
118+
ExcludeByAttribute.Add(attribute);
119+
return this;
120+
}
121+
122+
/// <summary>
123+
/// Adds a filter to the list of inclusions
124+
/// </summary>
125+
/// <param name="file">The filter to add</param>
126+
/// <returns></returns>
127+
public CoverletSettings WithInclusion(string file)
128+
{
129+
Include.Add(file);
130+
return this;
131+
}
132+
133+
/// <summary>
134+
/// Add a type of threshold to combine with the existing
135+
/// </summary>
136+
/// <param name="type">The type of threshold to add</param>
137+
/// <returns></returns>
138+
public CoverletSettings WithThresholdType(ThresholdType type)
139+
{
140+
ThresholdType |= type;
141+
return this;
142+
}
143+
144+
/// <summary>
145+
/// Add a type of format to combine with the existing output formats
146+
/// </summary>
147+
/// <param name="format">The format type to add</param>
148+
/// <returns></returns>
149+
public CoverletSettings WithFormat(CoverletOutputFormat format)
150+
{
151+
CoverletOutputFormat |= format;
152+
return this;
153+
}
154+
155+
/// <summary>
156+
/// Add a default transformer appending the current date time at the time of calling test
157+
/// </summary>
158+
/// <returns></returns>
159+
public CoverletSettings WithDateTimeTransformer()
160+
{
161+
OutputTransformer = (fileName, directory) => $@"{directory}\{fileName}-{DateTime.UtcNow:dd-MM-yyyy-HH-mm-ss-FFF}";
162+
return this;
163+
}
164+
165+
/// <summary>
166+
/// Sets the output format to be a specific value
167+
/// </summary>
168+
/// <param name="format"></param>
169+
/// <returns></returns>
170+
public CoverletSettings SetFormat(CoverletOutputFormat format)
171+
{
172+
CoverletOutputFormat = format;
173+
return this;
174+
}
175+
176+
/// <summary>
177+
/// Sets the output format to be a specific value
178+
/// </summary>
179+
/// <param name="includeTestAssembly"></param>
180+
/// <returns></returns>
181+
public CoverletSettings WithIncludeTestAssembly(bool includeTestAssembly)
182+
{
183+
IncludeTestAssembly = includeTestAssembly;
184+
return this;
185+
}
186+
187+
/// <summary>
188+
/// Clones the coverlet settings to a new instance
189+
/// </summary>
190+
/// <returns></returns>
191+
public CoverletSettings Clone() => new()
192+
{
193+
CollectCoverage = CollectCoverage,
194+
CoverletOutputFormat = CoverletOutputFormat,
195+
Threshold = Threshold,
196+
ThresholdType = ThresholdType,
197+
CoverletOutputDirectory = CoverletOutputDirectory == null ? null : DirectoryPath.FromString(CoverletOutputDirectory.FullPath),
198+
CoverletOutputName = CoverletOutputName,
199+
Include = new List<string>(Include),
200+
ExcludeByFile = new List<string>(ExcludeByFile),
201+
ExcludeByAttribute = new List<string>(ExcludeByAttribute),
202+
Exclude = new List<string>(Exclude),
203+
IncludeTestAssembly = IncludeTestAssembly,
204+
MergeWithFile = MergeWithFile == null ? null : FilePath.FromString(MergeWithFile.FullPath),
205+
OutputTransformer = OutputTransformer
206+
};
207+
}

build/common/Utilities/BuildLifetimeBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Common.Utilities;
55

66
public class BuildLifetimeBase<T> : FrostingLifetime<T> where T : BuildContextBase
77
{
8-
public override void Setup(T context)
8+
public override void Setup(T context, ISetupContext info)
99
{
1010
var buildSystem = context.BuildSystem();
1111
context.IsLocalBuild = buildSystem.IsLocalBuild;

build/common/Utilities/ContextExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Cake.Common.Tools.DotNet.Test;
2-
using Cake.Coverlet;
32
using Common.Addins.Cake.Coverlet;
43
using Xunit;
4+
using CoverletSettings = Common.Addins.Cake.Coverlet.CoverletSettings;
55

66
namespace Common.Utilities;
77

@@ -18,7 +18,7 @@ public static void DotNetTest(
1818
throw new ArgumentNullException(nameof(context));
1919
}
2020
var currentCustomization = settings.ArgumentCustomization;
21-
settings.ArgumentCustomization = (args) => ArgumentsProcessor.ProcessMSBuildArguments(
21+
settings.ArgumentCustomization = (args) => ArgumentsProcessor.ProcessMsBuildArguments(
2222
coverletSettings,
2323
context.Environment,
2424
currentCustomization?.Invoke(args) ?? args,

build/common/common.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Cake.Coverlet"/>
10-
<PackageReference Include="xunit.assert"/>
9+
<PackageReference Include="Cake.Coverlet" />
10+
<PackageReference Include="xunit.assert" />
1111
</ItemGroup>
1212

1313
</Project>

build/docker/BuildLifetime.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ namespace Docker;
44

55
public class BuildLifetime : BuildLifetimeBase<BuildContext>
66
{
7-
public override void Setup(BuildContext context)
7+
public override void Setup(BuildContext context, ISetupContext info)
88
{
9-
base.Setup(context);
9+
base.Setup(context, info);
1010

1111
context.IsDockerOnLinux = context.DockerCustomCommand("info --format '{{.OSType}}'").First().Replace("'", "") == "linux";
1212

0 commit comments

Comments
 (0)