-
Notifications
You must be signed in to change notification settings - Fork 152
/
build.cake
354 lines (307 loc) · 15.3 KB
/
build.cake
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
// Load the recipe
#load nuget:?package=NUnit.Cake.Recipe&version=1.2.1-dev00002
// Comment out above line and uncomment below for local tests of recipe changes
//#load ../NUnit.Cake.Recipe/recipe/*.cake
#load package-tests.cake
// Initialize BuildSettings
BuildSettings.Initialize(
Context,
title: "NUnit Console and Engine",
githubRepository: "nunit-console",
solutionFile: "NUnitConsole.sln",
exemptFiles: new[] { "Options.cs", "ProcessUtils.cs", "ProcessUtilsTests.cs" });
//////////////////////////////////////////////////////////////////////
// LISTS OF FILES USED IN CHECKING PACKAGES
//////////////////////////////////////////////////////////////////////
FilePath[] ConsoleFiles = {
"nunit3-console.dll", "nunit3-console.dll.config", "nunit3-console.exe", "nunit3-console.pdb",
"nunit3-console.deps.json", "nunit3-console.runtimeconfig.json" };
FilePath[] ENGINE_FILES = {
"nunit.engine.dll", "nunit.engine.core.dll", "nunit.engine.api.dll", "testcentric.engine.metadata.dll" };
FilePath[] ENGINE_PDB_FILES = {
"nunit.engine.pdb", "nunit.engine.core.pdb", "nunit.engine.api.pdb"};
FilePath[] ENGINE_CORE_FILES = {
"nunit.engine.core.dll", "nunit.engine.api.dll", "testcentric.engine.metadata.dll" };
FilePath[] ENGINE_CORE_PDB_FILES = {
"nunit.engine.core.pdb", "nunit.engine.api.pdb"};
FilePath[] AGENT_FILES = {
"nunit-agent.exe", "nunit-agent.exe.config",
"nunit-agent-x86.exe", "nunit-agent-x86.exe.config",
"nunit.engine.core.dll", "nunit.engine.api.dll", "testcentric.engine.metadata.dll"};
FilePath[] AGENT_FILES_NETCORE = {
"nunit-agent.dll", "nunit-agent.dll.config",
"nunit.engine.core.dll", "nunit.engine.api.dll", "testcentric.engine.metadata.dll",
"Microsoft.Extensions.DependencyModel.dll"};
FilePath[] AGENT_PDB_FILES = {
"nunit-agent.pdb", "nunit-agent-x86.pdb", "nunit.engine.core.pdb", "nunit.engine.api.pdb"};
FilePath[] AGENT_PDB_FILES_NETCORE = {
"nunit-agent.pdb", "nunit.engine.core.pdb", "nunit.engine.api.pdb"};
//////////////////////////////////////////////////////////////////////
// INDIVIDUAL PACKAGE DEFINITIONS
//////////////////////////////////////////////////////////////////////
PackageDefinition NUnitConsoleNuGetPackage;
PackageDefinition NUnitConsoleRunnerNuGetPackage;
PackageDefinition NUnitConsoleRunnerNetCorePackage;
PackageDefinition NUnitConsoleRunnerNet80Package;
PackageDefinition NUnitEnginePackage;
PackageDefinition NUnitEngineApiPackage;
PackageDefinition NUnitConsoleRunnerChocolateyPackage;
PackageDefinition NUnitConsoleZipPackage;
BuildSettings.Packages.AddRange(new PackageDefinition[] {
NUnitConsoleRunnerNuGetPackage = new NuGetPackage(
id: "NUnit.ConsoleRunner",
source: BuildSettings.NuGetDirectory + "runners/nunit.console-runner.nuspec",
checks: new PackageCheck[] {
HasFiles("LICENSE.txt", "NOTICES.txt"),
HasDirectory("tools").WithFiles("nunit3-console.exe", "nunit3-console.exe.config").AndFiles(ENGINE_FILES),
HasDirectory("tools/agents/net462").WithFiles(AGENT_FILES),
HasDirectory("tools/agents/netcoreapp3.1").WithFiles(AGENT_FILES_NETCORE),
HasDirectory("tools/agents/net6.0").WithFiles(AGENT_FILES_NETCORE),
HasDirectory("tools/agents/net7.0").WithFiles(AGENT_FILES_NETCORE),
HasDirectory("tools/agents/net8.0").WithFiles(AGENT_FILES_NETCORE)
},
symbols: new PackageCheck[] {
HasDirectory("tools").WithFiles(ENGINE_PDB_FILES).AndFile("nunit3-console.pdb"),
HasDirectory("tools/agents/net462").WithFiles(AGENT_PDB_FILES),
HasDirectory("tools/agents/netcoreapp3.1").WithFiles(AGENT_PDB_FILES_NETCORE),
HasDirectory("tools/agents/net6.0").WithFiles(AGENT_PDB_FILES_NETCORE),
HasDirectory("tools/agents/net7.0").WithFiles(AGENT_PDB_FILES_NETCORE),
HasDirectory("tools/agents/net8.0").WithFiles(AGENT_PDB_FILES_NETCORE)
},
testRunner: new ConsoleRunnerSelfTester(BuildSettings.NuGetTestDirectory
+ $"NUnit.ConsoleRunner.{BuildSettings.PackageVersion}/tools/nunit3-console.exe"),
tests: StandardRunnerTests),
// NOTE: Must follow ConsoleRunner, upon which it depends
NUnitConsoleNuGetPackage = new NuGetPackage(
id: "NUnit.Console",
source: BuildSettings.NuGetDirectory + "runners/nunit.console-runner-with-extensions.nuspec",
checks: new PackageCheck[] { HasFile("LICENSE.txt") }),
NUnitConsoleRunnerNetCorePackage = new DotNetToolPackage(
id: "NUnit.ConsoleRunner.NetCore",
source: BuildSettings.NuGetDirectory + "runners/nunit.console-runner.netcore.nuspec",
checks: new PackageCheck[]
{
HasFiles("nunit.exe"),
HasSomeDirectory(".store/nunit.consolerunner.netcore/**/tools/net8.0/any")
.WithFiles(ENGINE_FILES).AndFiles(ConsoleFiles).AndFile("Microsoft.Extensions.DependencyModel.dll")
},
testRunner: new ConsoleRunnerSelfTester(BuildSettings.NuGetTestDirectory
+ $"NUnit.ConsoleRunner.NetCore.{BuildSettings.PackageVersion}/nunit.exe"),
tests: NetCoreRunnerTests),
NUnitConsoleRunnerChocolateyPackage = new ChocolateyPackage(
id: "nunit-console-runner",
source: BuildSettings.ChocolateyDirectory + "nunit-console-runner.nuspec",
checks: new PackageCheck[] {
HasDirectory("tools").WithFiles("LICENSE.txt", "NOTICES.txt", "VERIFICATION.txt", "nunit3-console.exe", "nunit3-console.exe.config").AndFiles(ENGINE_FILES),
HasDirectory("tools/agents/net462").WithFiles(AGENT_FILES),
HasDirectory("tools/agents/netcoreapp3.1").WithFiles(AGENT_FILES_NETCORE),
HasDirectory("tools/agents/net6.0").WithFiles(AGENT_FILES_NETCORE),
HasDirectory("tools/agents/net7.0").WithFiles(AGENT_FILES_NETCORE),
HasDirectory("tools/agents/net8.0").WithFiles(AGENT_FILES_NETCORE)
},
testRunner: new ConsoleRunnerSelfTester(BuildSettings.ChocolateyTestDirectory
+ $"nunit-console-runner.{BuildSettings.PackageVersion}/tools/nunit3-console.exe"),
tests: StandardRunnerTests),
NUnitConsoleZipPackage = new ZipPackage(
id: "NUnit.Console",
source: BuildSettings.ZipImageDirectory,
checks: new PackageCheck[] {
HasFiles("LICENSE.txt", "NOTICES.txt", "CHANGES.txt"),
HasDirectory("bin/net462").WithFiles("nunit3-console.exe", "nunit3-console.exe.config",
"nunit3-console.pdb").AndFiles(ENGINE_FILES).AndFiles(ENGINE_PDB_FILES),
HasDirectory("bin/net462/addins").WithFiles(
"nunit.core.dll", "nunit.core.interfaces.dll", "nunit.engine.api.dll",
"nunit.v2.driver.dll", "nunit-project-loader.dll", "nunit-v2-result-writer.dll",
"teamcity-event-listener.dll", "vs-project-loader.dll"),
HasDirectory("bin/netcoreapp3.1").WithFiles(ENGINE_CORE_FILES).AndFiles(ENGINE_CORE_PDB_FILES),
HasDirectory("bin/agents/net462").WithFiles(AGENT_FILES).AndFiles(AGENT_PDB_FILES),
HasDirectory("bin/agents/net6.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE),
HasDirectory("bin/agents/net7.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE),
HasDirectory("bin/agents/net8.0").WithFiles(AGENT_FILES_NETCORE).AndFiles(AGENT_PDB_FILES_NETCORE),
},
testRunner: new ConsoleRunnerSelfTester(BuildSettings.ZipTestDirectory
+ $"NUnit.Console.{BuildSettings.PackageVersion}/bin/net462/nunit3-console.exe"),
tests: StandardRunnerTests,
bundledExtensions: new [] {
KnownExtensions.VSProjectLoader.NuGetPackage,
KnownExtensions.NUnitProjectLoader.NuGetPackage,
KnownExtensions.NUnitV2Driver.NuGetPackage,
KnownExtensions.NUnitV2ResultWriter.NuGetPackage,
KnownExtensions.TeamCityEventListener.NuGetPackage
}),
// NOTE: Packages below this point have no direct tests
NUnitEnginePackage = new NuGetPackage(
id: "NUnit.Engine",
source: BuildSettings.NuGetDirectory + "engine/nunit.engine.nuspec",
checks: new PackageCheck[] {
HasFiles("LICENSE.txt", "NOTICES.txt"),
HasDirectory("lib/net462").WithFiles(ENGINE_FILES),
HasDirectory("lib/net8.0").WithFiles(ENGINE_FILES).AndFile("Microsoft.Extensions.DependencyModel.dll"),
HasDirectory("contentFiles/any/agents/net462").WithFiles(AGENT_FILES)
},
symbols: new PackageCheck[] {
HasDirectory("lib/net462").WithFiles(ENGINE_PDB_FILES),
HasDirectory("lib/netstandard2.0").WithFiles(ENGINE_PDB_FILES),
HasDirectory("lib/net6.0").WithFiles(ENGINE_PDB_FILES),
HasDirectory("lib/net8.0").WithFiles(ENGINE_PDB_FILES),
HasDirectory("contentFiles/any/agents/net462").WithFiles(AGENT_PDB_FILES)
}),
NUnitEngineApiPackage = new NuGetPackage(
id: "NUnit.Engine.Api",
source: BuildSettings.NuGetDirectory + "engine/nunit.engine.api.nuspec",
checks: new PackageCheck[] {
HasFile("LICENSE.txt"),
HasDirectory("lib/net462").WithFile("nunit.engine.api.dll"),
HasDirectory("lib/netstandard2.0").WithFile("nunit.engine.api.dll"),
},
symbols: new PackageCheck[] {
HasDirectory("lib/net462").WithFile("nunit.engine.api.pdb"),
HasDirectory("lib/netstandard2.0").WithFile("nunit.engine.api.pdb")
})
});
Task("BuildZipPackage")
.Does(() =>
{
NUnitConsoleZipPackage.BuildPackage();
});
Task("InstallZipPackage")
.Does(() =>
{
NUnitConsoleZipPackage.InstallPackage();
});
Task("VerifyZipPackage")
.Does(() =>
{
NUnitConsoleZipPackage.VerifyPackage();
});
Task("TestZipPackage")
.Does(() =>
{
NUnitConsoleZipPackage.RunPackageTests();
});
Task("TestNetCorePackage")
.Does(() =>
{
NUnitConsoleRunnerNetCorePackage.RunPackageTests();
});
// Adhoc code to check content of a dotnet standalone executable
// TODO: Incorporate this in the recipe itself
private static ExtendedDirectoryCheck HasSomeDirectory(string pattern) => new ExtendedDirectoryCheck(pattern);
public class ExtendedDirectoryCheck : PackageCheck
{
private string _directoryPattern;
private List<FilePath> _files = new List<FilePath>();
public ExtendedDirectoryCheck(string directoryPattern)
{
// Assume it has no wildcard - checked in ApplyTo method
_directoryPattern = directoryPattern;
}
public ExtendedDirectoryCheck WithFiles(params FilePath[] files)
{
_files.AddRange(files);
return this;
}
public ExtendedDirectoryCheck AndFiles(params FilePath[] files)
{
return WithFiles(files);
}
public ExtendedDirectoryCheck WithFile(FilePath file)
{
_files.Add(file);
return this;
}
public ExtendedDirectoryCheck AndFile(FilePath file)
{
return AndFiles(file);
}
public override bool ApplyTo(DirectoryPath testDirPath)
{
if (_directoryPattern.Contains('*') || _directoryPattern.Contains('?')) // Wildcard
{
var absDirPattern = testDirPath.Combine(_directoryPattern).ToString();
foreach (var dir in _context.GetDirectories(absDirPattern))
{
// Use first one found
return CheckFilesExist(_files.Select(file => dir.CombineWithFilePath(file)));
}
}
else // No wildcard
{
var absDirPath = testDirPath.Combine(_directoryPattern);
if (!CheckDirectoryExists(absDirPath))
return false;
return CheckFilesExist(_files.Select(file => absDirPath.CombineWithFilePath(file)));
}
return false;
}
}
//////////////////////////////////////////////////////////////////////
// TEST RUNNERS
//////////////////////////////////////////////////////////////////////
// Use the console runner we just built to run package tests
public class ConsoleRunnerSelfTester : TestRunner, IPackageTestRunner
{
private string _executablePath;
public ConsoleRunnerSelfTester(string executablePath)
{
_executablePath = executablePath;
}
public int RunPackageTest(string arguments)
{
Console.WriteLine("Running package test");
return base.RunTest(_executablePath, arguments);
}
}
//////////////////////////////////////////////////////////////////////
// ADDITIONAL TARGETS USED FOR RECOVERY AND DEBUGGING
//////////////////////////////////////////////////////////////////////
// Some of these targets may be moved into the recipe itself in the future.
// When a NuGet package was published successfully but the corresponding symbols
// package failed, use this target locally after correcting the error.
// TODO: This task is extemely complicated because it has to copy lots of code
// from the recipe. It would be simpler if it were integrated in the recipe.
// TODO: This has been tested on NUnit.ConsoleRunner, so the branches with either
// zero or one packages are speculative at this point. They will need testing
// if this is incorporated into the recipe.
Task("PublishSymbolsPackage")
.Description("Re-publish a specific symbols package to NuGet after a failure")
.Does(() =>
{
if (!BuildSettings.ShouldPublishToNuGet)
Information("Nothing to publish to NuGet from this run.");
else if (CommandLineOptions.NoPush)
Information("NoPush option suppressing publication to NuGet");
else
{
List<PackageDefinition> packages;
if (BuildSettings.Packages.Count == 0)
throw new Exception("No packages exist!");
else if (BuildSettings.Packages.Count == 1)
{
if (BuildSettings.Packages[0].PackageType != PackageType.NuGet)
throw new Exception("The only package is not a NuGet package");
packages = BuildSettings.Packages;
}
else // count is > 1
{
if (!CommandLineOptions.PackageSelector.Exists)
throw new Exception("Multiple packages exist. Specify a nuget package id using the '--where' option");
packages = new List<PackageDefinition>();
foreach (var package in BuildSettings.Packages)
if (package.IsSelectedBy(CommandLineOptions.PackageSelector.Value))
packages.Add(package);
if (packages.Count > 1)
throw new Exception("The '--where' option selected multiple packages");
if (packages[0].PackageType != PackageType.NuGet)
throw new Exception("The selected package is a {package.PackageType} package. It must be a package for nuget.org.");
}
// At this point we have a single NuGet package in packages
var packageName = $"{packages[0].PackageId}.{BuildSettings.PackageVersion}.snupkg";
var packagePath = BuildSettings.PackageDirectory + packageName;
NuGetPush(packagePath, new NuGetPushSettings() { ApiKey = BuildSettings.NuGetApiKey, Source = BuildSettings.NuGetPushUrl });
}
});
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
Build.Run()