forked from TestCentric/testcentric-experimental-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
326 lines (273 loc) · 11.7 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
#tool nuget:?package=NUnit.ConsoleRunner&version=3.9.0
#tool nuget:?package=GitVersion.CommandLine
using System.Text.RegularExpressions;
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
//////////////////////////////////////////////////////////////////////
// SET PACKAGE VERSION DEFAULTS
//////////////////////////////////////////////////////////////////////
//GitVersion GitVersionInfo { get; set; }
//BuildInfo Build { get; set;} = new BuildInfo();
string version = "0.6.0";
string dbgSuffix = configuration == "Debug" ? "-dbg" : "";
string packageVersion = version + dbgSuffix;
//////////////////////////////////////////////////////////////////////
// BUILD ENVIRONMENT
//////////////////////////////////////////////////////////////////////
string monoVersion = null;
Type type = Type.GetType("Mono.Runtime");
if (type != null)
{
var displayName = type.GetMethod("GetDisplayName", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
if (displayName != null)
monoVersion = displayName.Invoke(null, null).ToString();
}
bool isMonoButSupportsMsBuild = monoVersion!=null && System.Text.RegularExpressions.Regex.IsMatch(monoVersion,@"^([5-9]|\d{2,})\.\d+\.\d+(\.\d+)?");
var msBuildSettings = new MSBuildSettings {
Verbosity = Verbosity.Minimal,
ToolVersion = MSBuildToolVersion.Default,//The highest available MSBuild tool version//VS2017
Configuration = configuration,
PlatformTarget = PlatformTarget.MSIL,
MSBuildPlatform = MSBuildPlatform.Automatic,
DetailedSummary = true,
};
if(!IsRunningOnWindows() && isMonoButSupportsMsBuild)
{
msBuildSettings.ToolPath = new FilePath(@"/usr/lib/mono/msbuild/15.0/bin/MSBuild.dll");//hack for Linux bug - missing MSBuild path
}
var xBuildSettings = new XBuildSettings {
Verbosity = Verbosity.Minimal,
ToolVersion = XBuildToolVersion.Default,//The highest available XBuild tool version//NET40
Configuration = configuration,
};
//////////////////////////////////////////////////////////////////////
// DEFINE RUN CONSTANTS
//////////////////////////////////////////////////////////////////////
// HACK: Engine Version - Must update this manually to match package used
var ENGINE_VERSION = "3.9.0";
// Directories
var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath + "/";
var PACKAGE_DIR = PROJECT_DIR + "package/";
var BIN_DIR = PROJECT_DIR + "bin/" + configuration + "/";
// Solution
var GUI_SOLUTION = PROJECT_DIR + "experimental-gui.sln";
// Test Assembly
var GUI_TESTS = BIN_DIR + "TestCentric.Gui.Tests.dll";
//////////////////////////////////////////////////////////////////////
// CLEAN
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
CleanDirectory(BIN_DIR);
});
//////////////////////////////////////////////////////////////////////
// RESTORE NUGET PACKAGES
//////////////////////////////////////////////////////////////////////
Task("RestorePackages")
.Does(() =>
{
NuGetRestore(GUI_SOLUTION, new NuGetRestoreSettings
{
Verbosity = NuGetVerbosity.Detailed
});
});
//////////////////////////////////////////////////////////////////////
// SET BUILD INFO
//////////////////////////////////////////////////////////////////////
//Task("SetBuildInfo")
// .Does(() =>
//{
// var settings = new GitVersionSettings();
// if (!BuildSystem.IsLocalBuild)
// {
// settings.UpdateAssemblyInfo = true;
// settings.UpdateAssemblyInfoFilePath = "src/CommonAssemblyInfo.cs";
// }
//
// GitVersionInfo = GitVersion(settings);
// Build = new BuildInfo(GitVersionInfo);
//});
//////////////////////////////////////////////////////////////////////
// BUILD
//////////////////////////////////////////////////////////////////////
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("RestorePackages")
//.IsDependentOn("SetBuildInfo")
.Does(() =>
{
if(IsRunningOnWindows() || isMonoButSupportsMsBuild)
{
MSBuild(GUI_SOLUTION, msBuildSettings);
}
else
{
XBuild(GUI_SOLUTION, xBuildSettings);
}
});
//////////////////////////////////////////////////////////////////////
// TEST
//////////////////////////////////////////////////////////////////////
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
NUnit3(GUI_TESTS);
});
//////////////////////////////////////////////////////////////////////
// PACKAGE
//////////////////////////////////////////////////////////////////////
Task("PackageZip")
.IsDependentOn("Build")
.Does(() =>
{
CreateDirectory(PACKAGE_DIR);
CopyFileToDirectory("LICENSE", BIN_DIR);
CopyFileToDirectory("CHANGES.txt", BIN_DIR);
CopyFileToDirectory("packages/NUnit.Engine." + ENGINE_VERSION + "/lib/nunit-agent.exe.config", BIN_DIR);
CopyFileToDirectory("packages/NUnit.Engine." + ENGINE_VERSION + "/lib/nunit-agent-x86.exe.config", BIN_DIR);
var zipFiles = new FilePath[]
{
BIN_DIR + "LICENSE",
BIN_DIR + "CHANGES.txt",
BIN_DIR + "tc-next.exe",
BIN_DIR + "tc-next.exe.config",
BIN_DIR + "TestCentric.Gui.Runner.dll",
BIN_DIR + "nunit.uikit.dll",
BIN_DIR + "TestCentric.Gui.Model.dll",
BIN_DIR + "nunit.engine.api.dll",
BIN_DIR + "nunit.engine.dll",
BIN_DIR + "Mono.Cecil.dll",
BIN_DIR + "nunit-agent.exe",
BIN_DIR + "nunit-agent.exe.config",
BIN_DIR + "nunit-agent-x86.exe",
BIN_DIR + "nunit-agent-x86.exe.config"
};
//Zip(BIN_DIR, File(PACKAGE_DIR + "testcentric-experimental-gui-" + Build.PackageVersion + ".zip"), zipFiles);
Zip(BIN_DIR, File(PACKAGE_DIR + "testcentric-experimental-gui-" + packageVersion + ".zip"), zipFiles);
});
Task("PackageChocolatey")
.IsDependentOn("Build")
.Does(() =>
{
CreateDirectory(PACKAGE_DIR);
ChocolateyPack("choco/testcentric-experimental-gui.nuspec",
new ChocolateyPackSettings()
{
//Version = Build.PackageVersion,
Version = packageVersion,
OutputDirectory = PACKAGE_DIR,
Files = new ChocolateyNuSpecContent[]
{
new ChocolateyNuSpecContent() { Source = "../LICENSE" },
new ChocolateyNuSpecContent() { Source = "../CHANGES.txt" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "tc-next.exe", Target="tools" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "tc-next.exe.config", Target="tools" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "TestCentric.Gui.Runner.dll", Target="tools"},
new ChocolateyNuSpecContent() { Source = BIN_DIR + "nunit.uikit.dll", Target="tools" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "TestCentric.Gui.Model.dll", Target="tools" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "nunit.engine.dll", Target="tools" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "nunit.engine.api.dll", Target="tools" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "Mono.Cecil.dll", Target="tools" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "nunit-agent.exe", Target="tools" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "nunit-agent.exe.config", Target="tools" },
new ChocolateyNuSpecContent() { Source = "nunit-agent.exe.ignore", Target="tools" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "nunit-agent-x86.exe", Target="tools" },
new ChocolateyNuSpecContent() { Source = BIN_DIR + "nunit-agent-x86.exe.config", Target="tools" },
new ChocolateyNuSpecContent() { Source = "nunit-agent-x86.exe.ignore", Target="tools" },
new ChocolateyNuSpecContent() { Source = "nunit.choco.addins", Target="tools" }
}
});
});
//////////////////////////////////////////////////////////////////////
// BUILD INFO
//////////////////////////////////////////////////////////////////////
class BuildInfo
{
public BuildInfo(GitVersion gitVersion)
{
Version = gitVersion.MajorMinorPatch;
BranchName = gitVersion.BranchName;
BuildNumber = gitVersion.CommitsSinceVersionSourcePadded;
// Initially assume it's neither master nor a PR
IsMaster = false;
IsPullRequest = false;
PullRequestNumber = string.Empty;
if (BranchName == "master")
{
IsMaster = true;
PreReleaseSuffix = "dev-" + BuildNumber;
}
else
{
var re = new Regex(@"(pull|pull\-requests?|pr)[/-](\d*)[/-]");
var match = re.Match(BranchName);
if (match.Success)
{
IsPullRequest = true;
PullRequestNumber = match.Groups[2].Value;
PreReleaseSuffix = "pr-" + PullRequestNumber + "-" + BuildNumber;
}
else
{
PreReleaseSuffix = "ci-" + BuildNumber + "-" + Regex.Replace(BranchName, "[^0-9A-Za-z-]+", "-");
// Nuget limits "special version part" to 20 chars.
if (PreReleaseSuffix.Length > 20)
PreReleaseSuffix = PreReleaseSuffix.Substring(0, 20);
}
}
PackageVersion = Version + "-" + PreReleaseSuffix;
AssemblyVersion = gitVersion.AssemblySemVer;
AssemblyFileVersion = PackageVersion;
}
public string BranchName { get; private set; }
public string Version { get; private set; }
public bool IsMaster { get; private set; }
public bool IsPullRequest { get; private set; }
public string PullRequestNumber { get; private set; }
public string BuildNumber { get; private set; }
public string PreReleaseSuffix { get; private set; }
public string PackageVersion { get; private set; }
public string AssemblyVersion { get; private set; }
public string AssemblyFileVersion { get; private set; }
public string Dump()
{
var NL = Environment.NewLine;
return " BranchName: " + BranchName + NL +
" Version: " + Version + NL +
" PreReleaseSuffix: " + PreReleaseSuffix + NL +
" IsPullRequest: " + IsPullRequest.ToString() + NL +
" PullRequestNumber: " + PullRequestNumber + NL +
" AssemblyVersion: " + AssemblyVersion + NL +
" AssemblyFileVersion: " + AssemblyFileVersion + NL +
" Package Version: " + PackageVersion + NL;
}
}
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Package")
.IsDependentOn("PackageZip")
.IsDependentOn("PackageChocolatey");
Task("Appveyor")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Package");
Task("Travis")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("PackageZip");
Task("All")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Package");
Task("Default")
.IsDependentOn("Build");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);