-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.cake
487 lines (419 loc) · 18 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#tool nuget:?package=NUnit.ConsoleRunner&version=3.8.0
#tool nuget:?package=NUnit.Extension.TeamCityEventListener&version=1.0.4
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
var msbuildPath = @"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe";
// Special (optional) arguments for the script. You pass these
// through the Cake bootscrap script via the -ScriptArgs argument
// for example:
// ./build.ps1 -t RePackageNuget -ScriptArgs --nugetVersion="3.9.9"
// ./build.ps1 -t RePackageNuget -ScriptArgs '--binaries="rel3.9.9" --nugetVersion="3.9.9"'
var nugetVersion = Argument("nugetVersion", (string)null);
var chocoVersion = Argument("chocoVersion", (string)null);
var binaries = Argument("binaries", (string)null);
//////////////////////////////////////////////////////////////////////
// SET PACKAGE VERSION
//////////////////////////////////////////////////////////////////////
var version = "1.0.9";
var modifier = "";
// Tuple(NUnit.Console version, NUnit version)
var versionsOfNunitCore = new [] {Tuple.Create("3.4.1", "3.4.1"), Tuple.Create("3.5", "3.5"), Tuple.Create("3.6", "3.6.1"), Tuple.Create("3.9", "3.8")};
// var versionsOfNunitCore = new [] {Tuple.Create("3.4.1", "3.4.1"), Tuple.Create("3.5", "3.5"), Tuple.Create("3.6", "3.6.1"), Tuple.Create("3.9", "3.8"), Tuple.Create("", "")};
var integrationTestsCategories = new List<string>();
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
var packageVersion = version + modifier + dbgSuffix;
if (BuildSystem.IsRunningOnAppVeyor)
{
var tag = AppVeyor.Environment.Repository.Tag;
if (tag.IsTag)
{
packageVersion = tag.Name;
}
else
{
var buildNumber = AppVeyor.Environment.Build.Number;
packageVersion = version + "-CI-" + buildNumber + dbgSuffix;
if (AppVeyor.Environment.PullRequest.IsPullRequest)
packageVersion += "-PR-" + AppVeyor.Environment.PullRequest.Number;
else
packageVersion += "-" + AppVeyor.Environment.Repository.Branch;
}
AppVeyor.UpdateBuildVersion(packageVersion);
}
//////////////////////////////////////////////////////////////////////
// DEFINE RUN CONSTANTS
//////////////////////////////////////////////////////////////////////
// Directories
var TARGET_FRAMEWORK = "net20";
var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
var PACKAGE_DIR = PROJECT_DIR + "package/";
var TOOLS_DIR = PROJECT_DIR + "tools/";
var BIN_CONFIG_DIR = PROJECT_DIR + "bin/" + configuration + "/";
var BIN_DIR = BIN_CONFIG_DIR + TARGET_FRAMEWORK + "/";
var BIN_SRC = BIN_CONFIG_DIR; // Source of binaries used in packaging
var TEST_NUNIT_DIR = PROJECT_DIR + "bin/nunit/";
var TEST_PACKAGES_DIR = PROJECT_DIR + "bin/packages/";
var TEST_TEAMCITY_EXT_DIR = TEST_NUNIT_DIR + "NUnit.Extension.TeamCityEventListener/tools/";
// Adjust BIN_SRC if --binaries option was given
if (binaries != null)
{
BIN_SRC = binaries;
if (!System.IO.Path.IsPathRooted(binaries))
{
BIN_SRC = PROJECT_DIR + binaries;
if (!BIN_SRC.EndsWith("/"))
BIN_SRC += "/";
}
}
// Files
var SOLUTION_FILE = PROJECT_DIR + "teamcity-event-listener.sln";
var TEST_SOLUTION_FILE = PROJECT_DIR + "teamcity-event-listener-tests.sln";
var NUNIT3_CONSOLE = TOOLS_DIR + "NUnit.ConsoleRunner.3.8.0/tools/nunit3-console.exe";
var TEST_ASSEMBLY = BIN_DIR + "teamcity-event-listener.tests.dll";
var INTEGRATION_TEST_ASSEMBLY = BIN_CONFIG_DIR + "nunit.integration.tests.dll";
// MetaData used in the nuget and chocolatey packages
var GITHUB_SITE = "https://github.com/nunit/teamcity-event-listener";
var WIKI_PAGE = "https://github.com/nunit/docs/wiki/Console-Command-Line";
var NUGET_ID = "NUnit.Extension.TeamCityEventListener";
var CHOCO_ID = "nunit-extension-teamcity-event-listener";
var TITLE = "NUnit 3 - Team City Event Listener Extension";
var AUTHORS = new [] { "Charlie Poole", "Nikolay Pianikov" };
var OWNERS = new [] { "Charlie Poole", "Nikolay Pianikov" };
var DESCRIPTION = "This extension sends specially formatted messages about test progress to TeamCity as each test executes, allowing TeamCity to monitor progress.";
var SUMMARY = "NUnit Team City Event Listener extension for TeamCity.";
var COPYRIGHT = "Copyright (c) 2017 Charlie Poole";
var RELEASE_NOTES = new [] { "See https://raw.githubusercontent.com/nunit/teamcity-event-listener/master/CHANGES.txt" };
var TAGS = new [] { "nunit", "test", "testing", "tdd", "runner" };
var PROJECT_URL = new Uri("http://nunit.org");
var ICON_URL = new Uri("https://cdn.rawgit.com/nunit/resources/master/images/icon/nunit_256.png");
var LICENSE_URL = new Uri("http://nunit.org/nuget/nunit3-license.txt");
var PROJECT_SOURCE_URL = new Uri( GITHUB_SITE );
var PACKAGE_SOURCE_URL = new Uri( GITHUB_SITE );
var BUG_TRACKER_URL = new Uri(GITHUB_SITE + "/issues");
var DOCS_URL = new Uri(WIKI_PAGE);
var MAILING_LIST_URL = new Uri("https://groups.google.com/forum/#!forum/nunit-discuss");
// Package sources for nuget restore
var PACKAGE_SOURCE = new string[]
{
"https://www.nuget.org/api/v2",
"https://www.myget.org/F/nunit/api/v2"
};
// Package sources for nuget restore
var PRERELEASE_PACKAGE_SOURCE = new string[]
{
"https://www.myget.org/F/nunit/api/v2",
"https://www.nuget.org/api/v2",
};
//////////////////////////////////////////////////////////////////////
// CLEAN
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(BIN_DIR);
});
//////////////////////////////////////////////////////////////////////
// INITIALIZE FOR BUILD
//////////////////////////////////////////////////////////////////////
Task("NuGetRestore")
.Does(() =>
{
NuGetRestore(SOLUTION_FILE, new NuGetRestoreSettings()
{
Source = PACKAGE_SOURCE
});
});
//////////////////////////////////////////////////////////////////////
// BUILD
//////////////////////////////////////////////////////////////////////
Task("Build")
.IsDependentOn("NuGetRestore")
.Does(() =>
{
if (binaries != null)
throw new Exception("The --binaries option may only be specified when re-packaging an existing build.");
if(IsRunningOnWindows())
{
MSBuild(SOLUTION_FILE, new MSBuildSettings{ ToolPath = msbuildPath }
.SetConfiguration(configuration)
.SetMSBuildPlatform(MSBuildPlatform.Automatic)
.SetVerbosity(Verbosity.Minimal)
.SetNodeReuse(false)
.SetPlatformTarget(PlatformTarget.MSIL)
.WithRestore()
);
}
else
{
XBuild(SOLUTION_FILE, new XBuildSettings()
.WithTarget("Build")
.WithProperty("Configuration", configuration)
.SetVerbosity(Verbosity.Minimal)
);
}
});
//////////////////////////////////////////////////////////////////////
// TEST
//////////////////////////////////////////////////////////////////////
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
int rc = StartProcess(
NUNIT3_CONSOLE,
new ProcessSettings()
{
Arguments = TEST_ASSEMBLY
});
if (rc != 0)
{
var message = rc > 0
? string.Format("Test failure: {0} tests failed", rc)
: string.Format("Test exited with rc = {0}", rc);
throw new CakeException(message);
}
});
//////////////////////////////////////////////////////////////////////
// INITIALIZE FOR BUILD
//////////////////////////////////////////////////////////////////////
Task("NuGetRestoreForIntegrationTests")
.Does(() =>
{
CleanDirectory(TEST_NUNIT_DIR);
NuGetRestore(TEST_SOLUTION_FILE, new NuGetRestoreSettings()
{
Source = PACKAGE_SOURCE
});
});
//////////////////////////////////////////////////////////////////////
// BUILD FOR INTEGRATION TEST
//////////////////////////////////////////////////////////////////////
Task("BuildForIntegrationTests")
.IsDependentOn("NuGetRestoreForIntegrationTests")
.Does(() =>
{
MSBuild(TEST_SOLUTION_FILE, new MSBuildSettings{ ToolPath = msbuildPath }
.SetConfiguration(configuration)
.SetVerbosity(Verbosity.Minimal)
.WithRestore()
);
});
//////////////////////////////////////////////////////////////////////
// ADD TEAMCITY TEST CATEGORY
//////////////////////////////////////////////////////////////////////
Task("AddTeamCityTestCategory")
.Does(() =>
{
integrationTestsCategories.Add("cat==teamcity");
});
//////////////////////////////////////////////////////////////////////
// INTEGRATION TEST
//////////////////////////////////////////////////////////////////////
Task("IntegrationTest")
.IsDependentOn("Build")
.IsDependentOn("BuildForIntegrationTests")
.Does(() =>
{
foreach(var nunitCoreVersion in versionsOfNunitCore)
{
EnsureDirectoryExists(TEST_NUNIT_DIR);
EnsureDirectoryExists(TEST_PACKAGES_DIR);
CleanDirectories(TEST_NUNIT_DIR + "**/*.*");
CleanDirectories(TEST_PACKAGES_DIR + "**/*.*");
Information("Restoring basic packages to test");
NuGetInstall(new [] {"NUnit" }, new NuGetInstallSettings()
{
Version = nunitCoreVersion.Item1 == string.Empty ? null : nunitCoreVersion.Item1,
OutputDirectory = TEST_NUNIT_DIR,
Source = nunitCoreVersion.Item1 == string.Empty ? PRERELEASE_PACKAGE_SOURCE : PACKAGE_SOURCE,
Prerelease = (nunitCoreVersion.Item1 == string.Empty),
NoCache = true
});
NuGetInstall(new [] {"NUnit.Console" }, new NuGetInstallSettings()
{
Version = nunitCoreVersion.Item2 == string.Empty ? null : nunitCoreVersion.Item2,
OutputDirectory = TEST_NUNIT_DIR,
Source = nunitCoreVersion.Item2 == string.Empty ? PRERELEASE_PACKAGE_SOURCE : PACKAGE_SOURCE,
Prerelease = (nunitCoreVersion.Item2 == string.Empty),
NoCache = true
});
Information("Restoring NUnit 2 packages");
NuGetInstall(new [] {"NUnit"}, new NuGetInstallSettings()
{
Version = "2.6.4",
OutputDirectory = TEST_PACKAGES_DIR,
Source = PACKAGE_SOURCE,
Prerelease = false,
NoCache = true
});
CleanDirectories(TEST_NUNIT_DIR + "NUnit.Extension.TeamCityEventListener*");
EnsureDirectoryExists(TEST_TEAMCITY_EXT_DIR);
CopyFileToDirectory(BIN_DIR + "teamcity-event-listener.dll", TEST_TEAMCITY_EXT_DIR);
var versionCategories = string.Join(
"||",
versionsOfNunitCore
.TakeWhile(i => i != nunitCoreVersion)
.Concat(Enumerable.Repeat(nunitCoreVersion, 1))
.Select(i => "cat==" + (string.IsNullOrEmpty(i.Item1) ? "dev" : i.Item1)));
var categoriesList =
integrationTestsCategories
.Concat(Enumerable.Repeat(versionCategories, 1))
.Where(i => !string.IsNullOrEmpty(i))
.Select(i => "(" + i + ")").ToList();
var arguments = INTEGRATION_TEST_ASSEMBLY;
if (categoriesList.Count!= 0)
{
arguments += " --where \"" + string.Join("&&", categoriesList) + "\"";
}
Information("NUnit arguments: " + arguments);
int rc = StartProcess(
NUNIT3_CONSOLE,
new ProcessSettings()
{
Arguments = arguments
});
if (rc != 0)
{
var message = rc > 0
? string.Format("Test failure: {0} tests failed", rc)
: string.Format("Test exited with rc = {0}", rc);
throw new CakeException(message);
}
try
{
using(var process = StartAndReturnProcess("TASKKILL", new ProcessSettings { Arguments = "/F /IM nunit-agent.exe /T" }))
{
Information("Kill nunit-agent.exe");
process.WaitForExit();
}
}
catch(Exception)
{
}
try
{
using(var process = StartAndReturnProcess("TASKKILL", new ProcessSettings { Arguments = "/F /IM nunit-agent-x86.exe /T" }))
{
Information("Kill nunit-agent-x86.exe");
process.WaitForExit();
}
}
catch(Exception)
{
}
}
});
//////////////////////////////////////////////////////////////////////
// PACKAGE
//////////////////////////////////////////////////////////////////////
Task("RePackageNuGet")
.IsDependentOn("Build")
.Does(() =>
{
CreateDirectory(PACKAGE_DIR);
NuGetPack(
new NuGetPackSettings()
{
Id = NUGET_ID,
Version = nugetVersion ?? packageVersion,
Title = TITLE,
Authors = AUTHORS,
Owners = OWNERS,
Description = DESCRIPTION,
Summary = SUMMARY,
ProjectUrl = PROJECT_URL,
IconUrl = ICON_URL,
LicenseUrl = LICENSE_URL,
RequireLicenseAcceptance = false,
Copyright = COPYRIGHT,
ReleaseNotes = RELEASE_NOTES,
Tags = TAGS,
//Language = "en-US",
OutputDirectory = PACKAGE_DIR,
Files = new [] {
new NuSpecContent { Source = PROJECT_DIR + "LICENSE.txt" },
new NuSpecContent { Source = PROJECT_DIR + "CHANGES.txt" },
new NuSpecContent { Source = PROJECT_DIR + ".addins", Target = "tools" },
new NuSpecContent { Source = BIN_SRC + "net20/teamcity-event-listener.dll", Target = "tools/net20" },
new NuSpecContent { Source = BIN_SRC + "net20/nunit.engine.api.dll", Target = "tools/net20" },
new NuSpecContent { Source = BIN_SRC + "netstandard2.0/teamcity-event-listener.dll", Target = "tools/netstandard2.0" },
new NuSpecContent { Source = BIN_SRC + "netstandard2.0/nunit.engine.api.dll", Target = "tools/netstandard2.0" }
}
});
});
Task("RePackageChocolatey")
.IsDependentOn("Build")
.Does(() =>
{
CreateDirectory(PACKAGE_DIR);
ChocolateyPack(
new ChocolateyPackSettings()
{
Id = CHOCO_ID,
Version = chocoVersion ?? packageVersion,
Title = TITLE,
Authors = AUTHORS,
Owners = OWNERS,
Description = DESCRIPTION,
Summary = SUMMARY,
ProjectUrl = PROJECT_URL,
IconUrl = ICON_URL,
LicenseUrl = LICENSE_URL,
RequireLicenseAcceptance = false,
Copyright = COPYRIGHT,
ProjectSourceUrl = PROJECT_SOURCE_URL,
DocsUrl= DOCS_URL,
BugTrackerUrl = BUG_TRACKER_URL,
PackageSourceUrl = PACKAGE_SOURCE_URL,
MailingListUrl = MAILING_LIST_URL,
ReleaseNotes = RELEASE_NOTES,
Tags = TAGS,
//Language = "en-US",
OutputDirectory = PACKAGE_DIR,
Files = new [] {
new ChocolateyNuSpecContent { Source = PROJECT_DIR + "LICENSE.txt", Target = "tools" },
new ChocolateyNuSpecContent { Source = PROJECT_DIR + "CHANGES.txt", Target = "tools" },
new ChocolateyNuSpecContent { Source = PROJECT_DIR + "VERIFICATION.txt", Target = "tools" },
new ChocolateyNuSpecContent { Source = PROJECT_DIR + ".addins", Target = "tools" },
new ChocolateyNuSpecContent { Source = BIN_SRC + "net20/teamcity-event-listener.dll", Target = "tools/net20" },
new ChocolateyNuSpecContent { Source = BIN_SRC + "net20/nunit.engine.api.dll", Target = "tools/net20" },
new ChocolateyNuSpecContent { Source = BIN_SRC + "netstandard2.0/teamcity-event-listener.dll", Target = "tools/netstandard2.0" },
new ChocolateyNuSpecContent { Source = BIN_SRC + "netstandard2.0/nunit.engine.api.dll", Target = "tools/netstandard2.0" }
}
});
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Rebuild")
.IsDependentOn("Clean")
.IsDependentOn("Build");
Task("Appveyor")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("AddTeamCityTestCategory")
.IsDependentOn("IntegrationTest")
.IsDependentOn("Package");
Task("CheckIntegration")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("IntegrationTest")
.IsDependentOn("Package");
Task("Package")
.IsDependentOn("Build")
.IsDependentOn("RePackage");
Task("RePackage")
.IsDependentOn("RePackageNuGet")
.IsDependentOn("RePackageChocolatey");
Task("Travis")
.IsDependentOn("Build")
.IsDependentOn("Test");
Task("Default")
.IsDependentOn("Build");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);