-
Notifications
You must be signed in to change notification settings - Fork 51
/
build.cake
443 lines (376 loc) · 16.2 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
// Pinned Coveralls version to older one because 1.0.0 has Error: One or more errors occurred. Package 'coveralls.net 1.0.0' has a package type 'DotnetTool' that is not supported by project 'C:/Projects/Computator.NET/tools'.
#addin nuget:?package=Cake.Coveralls&version=0.7.0
#addin nuget:?package=Cake.Codecov
#addin nuget:?package=Cake.AppPackager
#addin nuget:?package=Cake.VersionReader
#addin nuget:?package=Cake.FileHelpers
#tool nuget:?package=coveralls.net&version=0.7.0
#tool nuget:?package=OpenCover
#tool nuget:?package=NUnit.ConsoleRunner
#tool nuget:?package=Codecov
//////////////////////////////////////////////////////////////////////
// ENVIRONMENTAL VARIABLES
//////////////////////////////////////////////////////////////////////
var coverallsRepoToken = EnvironmentVariable("COVERALLS_REPO_TOKEN");//"KEH5rJaqCoWoCV2MhkrMlClj3SVIlB2Eu0YK4mqmhRM+ANEfGiFyROo2RWHkJXQz"
var configuration = (EnvironmentVariable("configuration") ?? EnvironmentVariable("build_config")) ?? "Release";
var travisOsName = EnvironmentVariable("TRAVIS_OS_NAME");
var dotNetCore = EnvironmentVariable("DOTNETCORE");
string monoVersion = null;
string monoVersionShort = 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();
Information("Mono version is "+monoVersion);
monoVersionShort = string.Join(".",System.Text.RegularExpressions.Regex.Match(monoVersion,@"(\d+\.\d+(?:\.\d+(?:\.\d+)?)?)").Value.Split(".".ToCharArray(),StringSplitOptions.RemoveEmptyEntries).Take(3));
Information("Mono version short is "+monoVersionShort);
}
}
var isMonoButSupportsMsBuild = monoVersion!=null && System.Text.RegularExpressions.Regex.IsMatch(monoVersion,@"^\s*([5-9]|\d{2,})\.\d+\.\d+(\.\d+)?");
var normalNUnit3Settings = new NUnit3Settings()
{
DisposeRunners = true,
Configuration = configuration,
Labels = NUnit3Labels.All,
//NoResults = true
};
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Define directories.
var solution = "Computator.NET.sln";
var mainProject = "Computator.NET/Computator.NET.csproj";
var mainProjectNet40 = "Computator.NET/Computator.NET.net40.csproj";
var mainProjectBinPath = @"Computator.NET/bin/" + configuration + @"/v4.6.1";
var mainProjectBinPathNet40 = @"Computator.NET/bin/" + configuration + @"/v4.0";
var installerProject = "Computator.NET.Installer/Computator.NET.Installer.csproj";
var unitTestsProject = "Computator.NET.Core.Tests/Computator.NET.Core.Tests.csproj";
var integrationTestsProject = "Computator.NET.Core.IntegrationTests/Computator.NET.Core.IntegrationTests.csproj";
var webApiIntegrationTestsProject = "Computator.NET.WebApi.IntegrationTests/Computator.NET.WebApi.IntegrationTests.csproj";
var allTestsBinaries = "**/bin/" + configuration+ "/**/Computator.NET*Test*.dll";
var integrationTestsBinaries = "Computator.NET*.IntegrationTests/"+"bin/" + configuration+ "/**/Computator.NET*Test*.dll";
var unitTestsBinaries = "Computator.NET*.Tests/"+"bin/" + configuration+ "/**/Computator.NET*Test*.dll";
var allWebTestsBinaries = "Computator.NET.Web*.*Tests*/"+"bin/" + configuration+ "/**/Computator.NET*Test*.dll";
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)
{
if(travisOsName == "osx" || System.Environment.OSVersion.Platform == System.PlatformID.MacOSX)
{
var msBuildVersions = new [] {"15.9","15.8","15.7","15.6","15.5","15.4","15.3","15.2","15.1","15.0"};
var monoVersions = new [] {"Current", monoVersionShort};
var msBuildExecutableNames = new [] {"MSBuild.exe", "MSBuild.dll", "msBuild.exe", "msbuild.exe", "msBuild.dll", "msbuild.dll"};
var msBuildPossiblePaths = new List<string>();
foreach(var msBuildVersion in msBuildVersions)
{
foreach(var msBuildExecutableName in msBuildExecutableNames)
{
foreach(var chosenMonoVersion in monoVersions)
{
msBuildPossiblePaths.Add(@"/Library/Frameworks/Mono.framework/Versions/" + chosenMonoVersion + @"/lib/mono/msbuild/" + msBuildVersion +@"/bin/"+msBuildExecutableName);
msBuildPossiblePaths.Add(@"/Library/Frameworks/Mono.framework/Versions/" + chosenMonoVersion + @"/bin/mono/msbuild/" + msBuildVersion +@"/bin/"+msBuildExecutableName);
}
msBuildPossiblePaths.Add(@"/usr/bin/mono/msbuild/"+msBuildVersion+@"/bin/"+msBuildExecutableName);
msBuildPossiblePaths.Add(@"/usr/local/bin/mono/msbuild/"+msBuildVersion+@"/bin/"+msBuildExecutableName);
msBuildPossiblePaths.Add(@"/usr/lib/mono/msbuild/"+msBuildVersion+@"/bin/"+msBuildExecutableName);
msBuildPossiblePaths.Add(@"/usr/local/lib/mono/msbuild/"+msBuildVersion+@"/bin/"+msBuildExecutableName);
}
}
var msBuildPath = msBuildPossiblePaths.FirstOrDefault(p => FileExists(p));
if(msBuildPath!=null)
{
Information("MSBuild path is "+msBuildPath);
msBuildSettings.ToolPath = new FilePath(msBuildPath);
}
else
Error("MSBuild path not found!");
}
else
msBuildSettings.ToolPath = new FilePath(@"/usr/lib/mono/msbuild/15.0/bin/MSBuild.dll");//hack for Linux bug - missing MSBuild path
}
var monoEnvVars = new Dictionary<string,string>() { {"DISPLAY", "99.0"},{"MONO_WINFORMS_XIM_STYLE", "disabled"} };
if(!IsRunningOnWindows())
{
if(msBuildSettings.EnvironmentVariables==null)
msBuildSettings.EnvironmentVariables = new Dictionary<string,string>();
foreach(var monoEnvVar in monoEnvVars)
{
msBuildSettings.EnvironmentVariables.Add(monoEnvVar.Key,monoEnvVar.Value);
}
}
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Install-Linux")
.Does(() =>
{
StartProcess("sudo", "apt-get install git-all");
StartProcess("git", "pull");
StartProcess("sudo", @"apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF");
StartProcess("echo", @"""deb http://download.mono-project.com/repo/debian wheezy main"" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list");
StartProcess("echo", @"""deb http://download.mono-project.com/repo/debian wheezy-apache24-compat main"" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list");
StartProcess("sudo", "apt-get install libgcc1-*");
StartProcess("sudo", "apt-get install libc6-*");
StartProcess("sudo", "apt-get install mono-complete");
StartProcess("sudo", "apt-get install monodevelop --fix-missing");
StartProcess("sudo", "apt-get install libmono-webbrowser4.0-cil");
StartProcess("sudo", "apt-get install libgluezilla");
StartProcess("sudo", "apt-get install curl");
StartProcess("sudo", "apt-get install libgtk2.0-dev");
});
Task("Clean")
.Does(() =>
{
DeleteDirectories(GetDirectories("Computator.NET*/**/bin"), recursive:true);
DeleteDirectories(GetDirectories("Computator.NET*/**/obj"), recursive:true);
DeleteDirectories(GetDirectories("AppPackages"), recursive:true);
//DeleteDirectories(GetDirectories("publish"), recursive:true);
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
if(dotNetCore=="1")
StartProcess("dotnet", "restore "+solution);
else
NuGetRestore("./"+solution);
if (travisOsName == "linux")
{
StartProcess("sudo", "apt-get install libgsl2");
System.Environment.SetEnvironmentVariable("DISPLAY", "99.0", System.EnvironmentVariableTarget.Process);//StartProcess("export", "DISPLAY=:99.0");
var xvfvProcessSettings = new ProcessSettings() { Arguments="--start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16" };
if(xvfvProcessSettings.EnvironmentVariables==null)
xvfvProcessSettings.EnvironmentVariables=new Dictionary<string,string>();
foreach(var envVar in monoEnvVars)
xvfvProcessSettings.EnvironmentVariables.Add(envVar.Key, envVar.Value);
StartProcess(@"/sbin/start-stop-daemon", xvfvProcessSettings);
System.Environment.SetEnvironmentVariable("DISPLAY", "99.0", System.EnvironmentVariableTarget.Process);//StartProcess("export", "DISPLAY=:99.0");
StartProcess("sleep", "3");//give xvfb some time to start
}
else if(travisOsName == "osx")
{
StartProcess("brew", "install gsl");
}
if(travisOsName=="linux" || travisOsName=="osx")
System.Environment.SetEnvironmentVariable("MONO_WINFORMS_XIM_STYLE", "disabled", System.EnvironmentVariableTarget.Process);//StartProcess("export", "MONO_WINFORMS_XIM_STYLE=disabled");
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
// Use MSBuild
MSBuild(mainProject, msBuildSettings);
MSBuild(mainProjectNet40, msBuildSettings);
MSBuild(unitTestsProject, msBuildSettings);
MSBuild(integrationTestsProject, msBuildSettings);
MSBuild(webApiIntegrationTestsProject, msBuildSettings);
});
Task("UnitTests")
.IsDependentOn("Build")
.Does(() =>
{
NUnit3(unitTestsBinaries, normalNUnit3Settings);
if(AppVeyor.IsRunningOnAppVeyor)
{
AppVeyor.UploadTestResults("./TestResult.xml", AppVeyorTestResultsType.NUnit3);
}
});
Task("IntegrationTests")
.IsDependentOn("Build")
.Does(() =>
{
NUnit3(integrationTestsBinaries, normalNUnit3Settings);
if(AppVeyor.IsRunningOnAppVeyor)
{
AppVeyor.UploadTestResults("./TestResult.xml", AppVeyorTestResultsType.NUnit3);
}
});
Task("AllTests")
.IsDependentOn("Build")
.Does(() =>
{
NUnit3(allTestsBinaries, normalNUnit3Settings);
if(AppVeyor.IsRunningOnAppVeyor)
{
AppVeyor.UploadTestResults("./TestResult.xml", AppVeyorTestResultsType.NUnit3);
}
});
Task("WebTests")
.IsDependentOn("Build")
.Does(() =>
{
NUnit3(allWebTestsBinaries, normalNUnit3Settings);
if(AppVeyor.IsRunningOnAppVeyor)
{
AppVeyor.UploadTestResults("./TestResult.xml", AppVeyorTestResultsType.NUnit3);
}
});
Task("Calculate-Coverage")
.IsDependentOn("Build")
.Does(() =>
{
OpenCover(tool => {
tool.NUnit3(allTestsBinaries,
new NUnit3Settings {
NoResults = true,
//InProcess = true,
//Domain = Domain.Single,
Where = "cat!=LongRunningTests",
ShadowCopy = false,
});
},
new FilePath("coverage.xml"),
(new OpenCoverSettings()
{
Register="user",
SkipAutoProps = true,
})
.WithFilter("+[Computator.NET*]*")
.WithFilter("-[Computator.NET.Core]Computator.NET.Core.Properties.*")
.WithFilter("-[Computator.NET.Localization]*")
.WithFilter("-[Computator.NET.Core.Tests]*")
.WithFilter("-[Computator.NET.Core.IntegrationTests]*")
.ExcludeByAttribute("*.ExcludeFromCodeCoverage*"));
});
Task("Upload-Coverage")
.IsDependentOn("Calculate-Coverage")
.Does(() =>
{
CoverallsNet("coverage.xml", CoverallsNetReportType.OpenCover, new CoverallsNetSettings()
{
RepoToken = coverallsRepoToken
});
Codecov("coverage.xml");
});
Task("Build-Installer")
.IsDependentOn("Build")
.Does(() =>
{
if(IsRunningOnWindows())
{
// Use MSBuild
//msBuildSettings.ArgumentCustomization=null;
MSBuild(installerProject, 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,
});
}
else
{
Warning("Building installer is currently not supported on Unix");
}
});
Task("Build-Uwp")
.IsDependentOn("Build")
.Does(() =>
{
if(IsRunningOnWindows())
{
var packageFiles = @"AppPackages/PackageFiles";
CopyDirectory(mainProjectBinPath,packageFiles);
CopyFileToDirectory(@"build-uwp/AppxManifest.xml",packageFiles);
CopyFileToDirectory(@"build-uwp/Registry.dat",packageFiles);
CopyDirectory(@"Computator.NET.Core/Special/windows-x64",packageFiles);
CopyDirectory(@"Graphics/Assets",packageFiles+@"/Assets");
CopyDirectory(@"Computator.NET.Core/TSL Examples",packageFiles+@"/VFS/Users/ContainerAdministrator/Documents/Computator.NET/TSL Examples");
var programFilesPath = System.Environment.Is64BitOperatingSystem ? Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
var makePriPaths = GetFiles(programFilesPath + @"\Windows Kits\10\bin\x86\makepri.exe");
var makePriPath = makePriPaths.First();
StartProcess(makePriPath, @"createconfig /cf AppPackages\PackageFiles\priconfig.xml /dq en-US");//makepri createconfig /cf AppPackages\PackageFiles\priconfig.xml /dq en-US
StartProcess(makePriPath, @"new /pr AppPackages\PackageFiles /cf AppPackages\PackageFiles\priconfig.xml");//makepri new /pr AppPackages\PackageFiles /cf AppPackages\PackageFiles\priconfig.xml
MoveFiles(@"*.pri", packageFiles);// move /y .\*.pri AppPackages\PackageFiles
AppPack("AppPackages/Computator.NET.x64.appx", new DirectoryPath("AppPackages/PackageFiles"));
//build another for x86
CopyDirectory(@"Computator.NET.Core/Special/windows-x86", packageFiles);
ReplaceTextInFiles(packageFiles+"/AppxManifest.xml","x64","x86");
AppPack("AppPackages/Computator.NET.x86.appx", new DirectoryPath("AppPackages/PackageFiles"));
Sign(GetFiles("AppPackages/*.appx"), new SignToolSignSettings {
TimeStampUri = new Uri("http://timestamp.digicert.com"),
DigestAlgorithm = SignToolDigestAlgorithm.Sha256,
CertPath = @"build-uwp/Computator.NET_TemporaryKey.pfx",
});
}
else
{
Warning("Building Universal Windows App is currently not supported on Unix");
}
});
Task("Publish")
.IsDependentOn("Build")
.Does(() =>
{
DeleteDirectories(GetDirectories("publish"), recursive:true);
var versionNumber = GetFullVersionNumber(mainProjectBinPath+@"/Computator.NET.exe");
var versionNumberNet40 = GetFullVersionNumber(mainProjectBinPathNet40+@"/Computator.NET.exe");
if(versionNumber!=versionNumberNet40)
Error("Version numbers for main executable differ for normal and NET40 build!");
EnsureDirectoryExists("publish");
var namesSuffix = ".v" + versionNumber + ".";
var namesSuffixNet40 = ".v" + versionNumber + (IsRunningOnWindows() ? "-WindowsXP" : "-net40") + ".";
//Publish Portable
var zipPublishPath = @"publish/Computator.NET" + namesSuffix + "zip";
var zipPublishPathNet40 = @"publish/Computator.NET" + namesSuffixNet40 + "zip";
Zip(mainProjectBinPath, zipPublishPath);
Zip(mainProjectBinPathNet40, zipPublishPathNet40);
if(AppVeyor.IsRunningOnAppVeyor)
{
AppVeyor.UploadArtifact(zipPublishPath);
AppVeyor.UploadArtifact(zipPublishPathNet40);
}
else if(TravisCI.IsRunningOnTravisCI)
Warning("Publishing artifacts in TravisCI is not yet supported.");
//Publish UWP
if(IsRunningOnWindows())
{
var appxX86PublishPath = "publish/Computator.NET" + namesSuffix + "x86.appx";
var appxX64PublishPath = "publish/Computator.NET" + namesSuffix + "x64.appx";
RunTarget("Build-Uwp");
MoveFile(@"AppPackages/Computator.NET.x86.appx", appxX86PublishPath);
MoveFile(@"AppPackages/Computator.NET.x64.appx", appxX64PublishPath);
if(AppVeyor.IsRunningOnAppVeyor)
{
AppVeyor.UploadArtifact(appxX64PublishPath);
AppVeyor.UploadArtifact(appxX86PublishPath);
}
}
else
Warning("Publishing UWP app is not supported on Unix.");
//Publish Installer
if(IsRunningOnWindows())
{
RunTarget("Build-Installer");
var installerPublishPath = @"publish/Computator.NET.Installer" + namesSuffix + "exe";
MoveFile(GetFiles(@"Computator.NET.Installer/bin/" + configuration + @"/Computator.NET.Installer.exe").Single(),installerPublishPath);
if(AppVeyor.IsRunningOnAppVeyor)
AppVeyor.UploadArtifact(installerPublishPath);
}
else
Warning("Publishing Installer is not supported on Unix.");
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("UnitTests");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);