forked from nunit/nunit3-vs-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
274 lines (224 loc) · 6.9 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
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
//////////////////////////////////////////////////////////////////////
// SET PACKAGE VERSION
//////////////////////////////////////////////////////////////////////
var version = "4.0.0";
var modifier = "";
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.ToString("00000");
var branch = AppVeyor.Environment.Repository.Branch.Replace(".", "").Replace("/", "");
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
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);
}
var packageName = "NUnit3TestAdapter-" + packageVersion;
//////////////////////////////////////////////////////////////////////
// DEFINE RUN CONSTANTS
//////////////////////////////////////////////////////////////////////
// Directories
var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
var PACKAGE_DIR = PROJECT_DIR + "package/";
var PACKAGE_IMAGE_DIR = PACKAGE_DIR + packageName + "/";
var SRC_DIR = PROJECT_DIR + "src/";
var TOOLS_DIR = PROJECT_DIR + "tools/";
var BIN_DIR = PROJECT_DIR + "bin/" + configuration + "/";
var DEMO_BIN_DIR = PROJECT_DIR + "demo/NUnitTestDemo/bin/" + configuration + "/";
// Solutions
var ADAPTER_SOLUTION = PROJECT_DIR + "NUnit3TestAdapter.sln";
var DEMO_SOLUTION = PROJECT_DIR + "demo/NUnit3TestDemo.sln";
// Test Runner
var NUNIT3_CONSOLE = TOOLS_DIR + "NUnit.ConsoleRunner/tools/nunit3-console.exe";
// Test Assemblies
var ADAPTER_TESTS = BIN_DIR + "NUnit.VisualStudio.TestAdapter.Tests.dll";
var DEMO_TESTS = DEMO_BIN_DIR + "NUnit3TestDemo.dll";
// Custom settings for VSTest
var VSTestCustomSettings = new VSTestSettings()
{
ArgumentCustomization = args => args.Append("/TestAdapterPath:" + BIN_DIR)
};
//////////////////////////////////////////////////////////////////////
// CLEAN
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(BIN_DIR);
CleanDirectory(DEMO_BIN_DIR);
});
//////////////////////////////////////////////////////////////////////
// INITIALIZE FOR BUILD
//////////////////////////////////////////////////////////////////////
Task("NuGetRestore")
.Does(() =>
{
NuGetRestore(ADAPTER_SOLUTION);
NuGetRestore(DEMO_SOLUTION);
});
//////////////////////////////////////////////////////////////////////
// BUILD
//////////////////////////////////////////////////////////////////////
Task("Build")
.IsDependentOn("NuGetRestore")
.Does(() =>
{
BuildSolution(ADAPTER_SOLUTION, configuration);
BuildSolution(DEMO_SOLUTION, configuration);
});
//////////////////////////////////////////////////////////////////////
// TEST
//////////////////////////////////////////////////////////////////////
Task("TestAdapterUsingConsole")
.IsDependentOn("Build")
.Does(() =>
{
int rc = StartProcess(
NUNIT3_CONSOLE,
new ProcessSettings()
{
Arguments = ADAPTER_TESTS
});
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);
}
});
Task("TestAdapterUsingVSTest")
.IsDependentOn("Build")
.Does(() =>
{
VSTest(ADAPTER_TESTS, VSTestCustomSettings);
});
Task("TestDemo")
.IsDependentOn("Build")
.Does(() =>
{
try
{
VSTest(DEMO_TESTS, VSTestCustomSettings);
}
catch(Exception ex)
{
Information("\nNOTE: Demo tests failed as expected.");
Information("This is normally not an error.\n");
}
});
//////////////////////////////////////////////////////////////////////
// PACKAGE
//////////////////////////////////////////////////////////////////////
Task("CreatePackageDir")
.Does(() =>
{
CreateDirectory(PACKAGE_DIR);
});
Task("CreateWorkingImage")
.IsDependentOn("CreatePackageDir")
.Does(() =>
{
CreateDirectory(PACKAGE_IMAGE_DIR);
CleanDirectory(PACKAGE_IMAGE_DIR);
CopyFileToDirectory("LICENSE.txt", PACKAGE_IMAGE_DIR);
var binFiles = new FilePath[]
{
BIN_DIR + "NUnit3.TestAdapter.dll",
BIN_DIR + "nunit.engine.dll",
BIN_DIR + "nunit.engine.api.dll",
BIN_DIR + "Mono.Cecil.dll",
BIN_DIR + "Mono.Cecil.Pdb.dll",
BIN_DIR + "Mono.Cecil.Mdb.dll",
BIN_DIR + "Mono.Cecil.Rocks.dll"
};
var binDir = PACKAGE_IMAGE_DIR + "bin/";
CreateDirectory(binDir);
CopyFiles(binFiles, binDir);
});
Task("PackageZip")
.IsDependentOn("CreateWorkingImage")
.Does(() =>
{
Zip(PACKAGE_IMAGE_DIR, File(PACKAGE_DIR + packageName + ".zip"));
});
Task("PackageNuGet")
.IsDependentOn("CreateWorkingImage")
.Does(() =>
{
NuGetPack("nuget/NUnit3TestAdapter.nuspec", new NuGetPackSettings()
{
Version = packageVersion,
BasePath = PACKAGE_IMAGE_DIR,
OutputDirectory = PACKAGE_DIR
});
});
Task("PackageVsix")
.IsDependentOn("CreatePackageDir")
.Does(() =>
{
CopyFile(
BIN_DIR + "NUnit3TestAdapter.vsix",
PACKAGE_DIR + packageName + ".vsix");
});
//////////////////////////////////////////////////////////////////////
// HELPER METHODS
//////////////////////////////////////////////////////////////////////
void BuildSolution(string solutionPath, string configuration)
{
DotNetBuild(solutionPath, settings =>
settings.SetConfiguration(configuration)
.WithTarget("Build")
.WithProperty("NodeReuse", "false"));
}
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Rebuild")
.IsDependentOn("Clean")
.IsDependentOn("Build");
Task("Test")
.IsDependentOn("TestAdapterUsingConsole")
.IsDependentOn("TestAdapterUsingVSTest");
Task("Package")
.IsDependentOn("PackageZip")
.IsDependentOn("PackageNuGet")
.IsDependentOn("PackageVsix");
Task("Appveyor")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Package");
Task("Default")
.IsDependentOn("Build");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);