forked from nunit-legacy/nunitv2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
387 lines (318 loc) · 12.1 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
#tool "nuget:?package=WiX.Toolset"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////
// CHANGE TO SET PACKAGE AND ASSEMBLY VERSIONS
//////////////////////////////////////////////////////////////////////
var version = "2.7.0";
var modifier = ""; // for example "-beta2"
var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
// Package version may be changed in Setup on AppVeyor
var packageVersion = version + modifier + dbgSuffix;
//////////////////////////////////////////////////////////////////////
// DEFINE RUN CONSTANTS
//////////////////////////////////////////////////////////////////////
var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
var SOLUTION_FILE = PROJECT_DIR + "nunitv2.sln";
var BIN_DIR = PROJECT_DIR + "bin/" + configuration + "/";
var NUNIT_CONSOLE = BIN_DIR + "nunit-console.exe";
var INSTALL_DIR = PROJECT_DIR + "install/";
var NUGET_DIR = PROJECT_DIR + "nuget/";
var PACKAGE_DIR = PROJECT_DIR + "package/";
//////////////////////////////////////////////////////////////////////
// SETUP
//////////////////////////////////////////////////////////////////////
// These are properties because SetUp can change packageVersion
string PackageBaseName
{
get { return "NUnit-" + packageVersion; }
}
string PackageWorkDir
{
get { return PACKAGE_DIR + PackageBaseName + "/"; }
}
//////////////////////////////////////////////////////////////////////
// SETUP
//////////////////////////////////////////////////////////////////////
Setup(context =>
{
if (BuildSystem.IsRunningOnAppVeyor)
{
var buildNumber = AppVeyor.Environment.Build.Number.ToString("00000");
var branch = AppVeyor.Environment.Repository.Branch;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
if (branch == "master" && !isPullRequest)
{
packageVersion = version + "-dev-" + buildNumber + dbgSuffix;
}
else
{
var suffix = "-ci-" + buildNumber + dbgSuffix;
if (isPullRequest)
suffix += "-pr-" + AppVeyor.Environment.PullRequest.Number;
else if (AppVeyor.Environment.Repository.Branch.StartsWith("release", StringComparison.OrdinalIgnoreCase))
suffix += "-pre-" + buildNumber;
else
suffix += "-" + branch;
// Nuget limits "special version part" to 20 chars. Add one for the hyphen.
if (suffix.Length > 21)
suffix = suffix.Substring(0, 21);
packageVersion = version + suffix;
}
AppVeyor.UpdateBuildVersion(packageVersion);
}
// Executed BEFORE the first task.
Information("Building {0} version {1} of NUnit.", configuration, packageVersion);
});
//////////////////////////////////////////////////////////////////////
// CLEAN
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Description("Deletes all files in the BIN directory")
.Does(() =>
{
CleanDirectory(BIN_DIR);
});
Task("CleanPackageWorkDir")
.Description("Deletes all files in the package work directory")
.Does(() =>
{
CleanDirectory(PackageWorkDir);
});
//////////////////////////////////////////////////////////////////////
// NUGET RESTORE
//////////////////////////////////////////////////////////////////////
Task("NuGetRestore")
.Description("Restores NuGet Packages")
.Does(() =>
{
NuGetRestore(SOLUTION_FILE);
});
//////////////////////////////////////////////////////////////////////
// Build
//////////////////////////////////////////////////////////////////////
Task("Build")
.Description("Builds the Solution")
.IsDependentOn("NuGetRestore")
.Does(() =>
{
MSBuild(SOLUTION_FILE, new MSBuildSettings()
.SetConfiguration(configuration)
.SetVerbosity(Verbosity.Minimal));
// Extra copies of some files are needed for backward compatibility
// and to avoid changing the structure of the MSI directories.
CopyFileToDirectory(BIN_DIR + "tests/NSubstitute.dll", BIN_DIR + "lib/");
// Copy in NUnit project files
CopyFile(PROJECT_DIR + "NUnitTests.v2.nunit", BIN_DIR + "NUnitTests.nunit");
CopyFile(PROJECT_DIR + "NUnitTests.config", BIN_DIR + "NUnitTests.config");
// Copy files for assembly load policy tests
var targetDir = BIN_DIR + "tests/loadpolicy/lib/";
CreateDirectory(targetDir);
CopyFileToDirectory(BIN_DIR + "tests/nunit.framework.dll", targetDir);
});
//////////////////////////////////////////////////////////////////////
// TEST
//////////////////////////////////////////////////////////////////////
Task("BasicTests")
.Description("Runs the tests")
.IsDependentOn("Build")
.Does(() =>
{
int rc = StartProcess(
NUNIT_CONSOLE,
new ProcessSettings()
{
WorkingDirectory = BIN_DIR,
Arguments = "NUnitTests.nunit"
});
if (rc > 0)
throw new Exception(string.Format("{0} tests failed", rc));
else if (rc < 0)
throw new Exception(string.Format("Console returned rc = {0}", rc));
});
Task("Net45Tests")
.Description("Runs the .NET 4.5 tests")
.IsDependentOn("Build")
.Does(() =>
{
int rc = StartProcess(
NUNIT_CONSOLE,
new ProcessSettings()
{
WorkingDirectory = BIN_DIR + "tests",
Arguments = "nunit.core.tests.net45.dll nunit.framework.tests.net45.dll -noxml -framework:net-4.5"
});
if (rc > 0)
throw new Exception(string.Format("{0} tests failed", rc));
else if (rc < 0)
throw new Exception(string.Format("Console returned rc = {0}", rc));
});
Task("CompatibilityTests")
.Description("Runs the compatibility tests")
.IsDependentOn("Build")
.Does(() =>
{
int rc = StartProcess(
NUNIT_CONSOLE,
new ProcessSettings()
{
WorkingDirectory = BIN_DIR + "tests",
Arguments = "compatibility-tests.dll -noxml -compatibility"
});
if (rc > 0)
throw new Exception(string.Format("{0} tests failed", rc));
else if (rc < 0)
throw new Exception(string.Format("Console returned rc = {0}", rc));
});
Task("AssemblyLoadPolicyTests")
.Description("Runs the assembly load policy tests")
.IsDependentOn("Build")
.Does(() =>
{
int rc = StartProcess(
NUNIT_CONSOLE,
new ProcessSettings()
{
WorkingDirectory = BIN_DIR + "tests/loadpolicy",
Arguments = "simple-assembly.dll -noxml"
});
if (rc > 0)
throw new Exception(string.Format("{0} tests failed", rc));
else if (rc < 0)
throw new Exception(string.Format("Console returned rc = {0}", rc));
});
//////////////////////////////////////////////////////////////////////
// Package
//////////////////////////////////////////////////////////////////////
// NOTE:
//
// The Package targets do NOT depend on the Build! It is necessary to ensure
// that the build is updated before running any of these targets.
//
// Furthermore, it is not sufficient to just run the build in the IDE. Rather,
// it must be done using this script, which copies additional files to the
// directories where they need to be in order for packaging to work.
Task("CreatePackageDir")
.Description("Creates the package directory")
.Does(() =>
{
CreateDirectory(PACKAGE_DIR);
});
Task("PackageSource")
.Description("Create Source Package")
.IsDependentOn("CreatePackageDir")
.Does(() =>
{
string zipOutput = PACKAGE_DIR + PackageBaseName + "-src.zip";
int rc = StartProcess("git", "archive --format=zip --output=" + zipOutput + " HEAD");
});
Task("BuildInstallImage")
.Description("Build the install image for zip or msi")
.IsDependentOn("CreatePackageDir")
.IsDependentOn("CleanPackageWorkDir")
.Does(() =>
{
CopyFiles(
new FilePath[] {
"license.txt",
"src/GuiRunner/nunit-gui/Logo.ico"
},
PackageWorkDir);
var binDir = PackageWorkDir + "bin/";
// TODO: Create a method to handle wildcard directories
CopyFilesToDirectory(BIN_DIR + "*", binDir);
CopyFilesToDirectory(BIN_DIR + "lib/*", binDir + "lib/");
CopyFilesToDirectory(BIN_DIR + "lib/Images/*", binDir + "lib/Images/");
CopyFilesToDirectory(BIN_DIR + "lib/Images/Tree/Circles/*", binDir + "lib/Images/Tree/Circles/");
CopyFilesToDirectory(BIN_DIR + "lib/Images/Tree/Classic/*", binDir + "lib/Images/Tree/Classic/");
CopyFilesToDirectory(BIN_DIR + "lib/Images/Tree/Default/*", binDir + "lib/Images/Tree/Default/");
CopyFilesToDirectory(BIN_DIR + "lib/Images/Tree/Visual Studio/*", binDir + "lib/Images/Tree/Visual Studio/");
CopyFilesToDirectory(BIN_DIR + "tests/*", binDir + "tests/");
CopyFilesToDirectory(BIN_DIR + "framework/*", binDir + "framework/");
});
Task("PackageZip")
.Description("Create Binary Zip Package")
.IsDependentOn("BuildInstallImage")
.Does(() =>
{
var zipOutput = PACKAGE_DIR + PackageBaseName + ".zip";
Zip(PackageWorkDir, zipOutput);
});
Task("PackageMsi")
.Description("Create the MSI Installer")
.IsDependentOn("BuildInstallImage")
.Does(() =>
{
WiXCandle(
INSTALL_DIR + "*.wxs",
new CandleSettings()
{
Defines = new Dictionary<string, string>()
{
{"ProductVersion", version},
{"NominalVersion", packageVersion},
{"TargetRuntime", "net-3.5"},
{"InstallImage", PackageWorkDir}
},
OutputDirectory = PackageWorkDir
});
WiXLight(
PackageWorkDir + "*.wixobj",
new LightSettings()
{
Extensions = new [] { "WixUiExtension" },
OutputFile = PACKAGE_DIR + PackageBaseName + ".msi"
});
});
Task("PackageNuGet")
.Description("Create the nuget packages")
.IsDependentOn("BuildInstallImage")
.Does(() =>
{
foreach (var nuspecFile in GetFiles(NUGET_DIR + "*.nuspec"))
NuGetPack(nuspecFile, new NuGetPackSettings()
{
Version = packageVersion,
BasePath = PackageWorkDir,
OutputDirectory = PACKAGE_DIR,
NoPackageAnalysis = true
});
});
//////////////////////////////////////////////////////////////////////
// HELPER METHODS
//////////////////////////////////////////////////////////////////////
void CopyFilesToDirectory(string pattern, string toDir)
{
if (!DirectoryExists(toDir))
CreateDirectory(toDir);
CopyFiles(pattern, toDir);
}
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Rebuild")
.IsDependentOn("Clean")
.IsDependentOn("Build");
Task("Test")
.IsDependentOn("BasicTests")
.IsDependentOn("Net45Tests")
.IsDependentOn("CompatibilityTests")
.IsDependentOn("AssemblyLoadPolicyTests");
Task("Package")
.IsDependentOn("PackageSource")
.IsDependentOn("PackageZip")
.IsDependentOn("PackageMsi")
.IsDependentOn("PackageNuGet");
Task("AppVeyor")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Package");
Task("Default")
.IsDependentOn("Build");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);