forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
436 lines (367 loc) · 14.8 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.
//////////////////////////////////////////////////////////////////////
// ADDINS
//////////////////////////////////////////////////////////////////////
#addin "nuget:?package=Cake.FileHelpers&version=2.0.0"
#addin "nuget:?package=Cake.Coveralls&version=0.8.0"
#addin "nuget:?package=Cake.PinNuGetDependency&version=3.0.1"
#addin "nuget:?package=Cake.Powershell&version=0.4.3"
//////////////////////////////////////////////////////////////////////
// TOOLS
//////////////////////////////////////////////////////////////////////
#tool "nuget:?package=GitReleaseManager&version=0.7.0"
#tool "nuget:?package=GitVersion.CommandLine&version=3.6.5"
#tool "nuget:?package=coveralls.io&version=1.4.2"
#tool "nuget:?package=OpenCover&version=4.6.519"
#tool "nuget:?package=ReportGenerator&version=3.1.2"
#tool "nuget:?package=vswhere&version=2.4.1"
#tool "nuget:?package=xunit.runner.console&version=2.4.0-beta.2.build3984"
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
if (string.IsNullOrWhiteSpace(target))
{
target = "Default";
}
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
// Should MSBuild treat any errors as warnings?
var treatWarningsAsErrors = false;
// Build configuration
var local = BuildSystem.IsLocalBuild;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
var isRepository = StringComparer.OrdinalIgnoreCase.Equals("reactiveui/reactiveui", AppVeyor.Environment.Repository.Name);
var isDevelopBranch = StringComparer.OrdinalIgnoreCase.Equals("develop", AppVeyor.Environment.Repository.Branch);
var isReleaseBranch = StringComparer.OrdinalIgnoreCase.Equals("master", AppVeyor.Environment.Repository.Branch);
var isTagged = AppVeyor.Environment.Repository.Tag.IsTag;
var githubOwner = "reactiveui";
var githubRepository = "reactiveui";
var githubUrl = string.Format("https://github.com/{0}/{1}", githubOwner, githubRepository);
var msBuildPath = VSWhereLatest().CombineWithFilePath("./MSBuild/15.0/Bin/MSBuild.exe");
// Version
var gitVersion = GitVersion();
var majorMinorPatch = gitVersion.MajorMinorPatch;
var informationalVersion = gitVersion.InformationalVersion;
var nugetVersion = gitVersion.NuGetVersionV2;
var buildVersion = gitVersion.FullBuildMetaData;
// Artifacts
var artifactDirectory = "./artifacts/";
var testCoverageOutputFile = artifactDirectory + "OpenCover.xml";
var packageWhitelist = new[] { "ReactiveUI.Testing",
"ReactiveUI.Events",
"ReactiveUI.Events.WPF",
"ReactiveUI.Events.XamForms",
"ReactiveUI",
"ReactiveUI.AndroidSupport",
"ReactiveUI.Blend",
"ReactiveUI.WPF",
"ReactiveUI.Winforms",
"ReactiveUI.XamForms" };
// Define global marcos.
Action Abort = () => { throw new Exception("a non-recoverable fatal error occurred."); };
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
if (!IsRunningOnWindows())
{
throw new NotImplementedException("ReactiveUI will only build on Windows (w/Xamarin installed) because it's not possible to target UWP, WPF and Windows Forms from UNIX.");
}
Information("Building version {0} of ReactiveUI. (isTagged: {1})", informationalVersion, isTagged);
CreateDirectory(artifactDirectory);
});
Teardown(context =>
{
// Executed AFTER the last task.
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("BuildEventBuilder")
.Does (() =>
{
var solution = "./src/EventBuilder.sln";
Information("Building {0} using {1}", solution, msBuildPath);
NuGetRestore(solution, new NuGetRestoreSettings() { ConfigFile = "./src/.nuget/NuGet.config" });
MSBuild(solution, new MSBuildSettings() {
ToolPath = msBuildPath,
ArgumentCustomization = args => args.Append("/bl:eventbuilder.binlog /m")
}
.SetConfiguration("Release")
.WithProperty("TreatWarningsAsErrors", treatWarningsAsErrors.ToString())
.SetVerbosity(Verbosity.Minimal)
.SetNodeReuse(false));
});
Task("GenerateEvents")
.IsDependentOn("BuildEventBuilder")
.Does (() =>
{
var eventBuilder = "./src/EventBuilder/bin/Release/net461/EventBuilder.exe";
var workingDirectory = "./src/EventBuilder/bin/Release/Net461";
var referenceAssembliesPath = VSWhereLatest().CombineWithFilePath("./Common7/IDE/ReferenceAssemblies/Microsoft/Framework");
Information(referenceAssembliesPath.ToString());
Action<string, string> generate = (string platform, string directory) =>
{
using(var process = StartAndReturnProcess(eventBuilder,
new ProcessSettings{
Arguments = new ProcessArgumentBuilder()
.AppendSwitch("--platform","=", platform)
.AppendSwitchQuoted("--reference","=", referenceAssembliesPath.ToString()),
WorkingDirectory = workingDirectory,
RedirectStandardOutput = true }))
{
// super important to ensure that the platform is always
// uppercase so that the events are written to the write
// filename as UNIX is case-sensitive - even though OSX
// isn't by default.
platform = platform.ToUpper();
Information("Generating events for '{0}'", platform);
int timeout = 10 * 60 * 1000; // x Minute, y Second, z Millisecond
process.WaitForExit(timeout);
var stdout = process.GetStandardOutput();
int success = 0; // exit code aka %ERRORLEVEL% or $?
if (process.GetExitCode() != success)
{
Error("Failed to generate events for '{0}'", platform);
foreach (var line in stdout)
{
Error(line);
}
Abort();
}
var filename = String.Format("Events_{0}.cs", platform);
var output = System.IO.Path.Combine(directory, filename);
FileWriteLines(output, stdout.ToArray());
Information("The events have been written to '{0}'", output);
}
};
generate("android", "src/ReactiveUI.Events/");
generate("ios", "src/ReactiveUI.Events/");
generate("mac", "src/ReactiveUI.Events/");
generate("uwp", "src/ReactiveUI.Events/");
generate("wpf", "src/ReactiveUI.Events.WPF/");
generate("xamforms", "src/ReactiveUI.Events.XamForms/");
});
Task("BuildReactiveUI")
.IsDependentOn("GenerateEvents")
.Does (() =>
{
Action<string,string> build = (solution, name) =>
{
Information("Building {0} using {1}", solution, msBuildPath);
MSBuild(solution, new MSBuildSettings() {
ToolPath = msBuildPath,
ArgumentCustomization = args => args.Append("/bl:reactiveui-build-" + name + ".binlog /m /restore")
}
.WithTarget("build;pack")
.WithProperty("PackageOutputPath", MakeAbsolute(Directory(artifactDirectory)).ToString().Quote())
.WithProperty("TreatWarningsAsErrors", treatWarningsAsErrors.ToString())
.SetConfiguration("Release")
// Due to https://github.com/NuGet/Home/issues/4790 and https://github.com/NuGet/Home/issues/4337 we
// have to pass a version explicitly
.WithProperty("Version", nugetVersion.ToString())
.WithProperty("InformationalVersion", informationalVersion)
.SetVerbosity(Verbosity.Minimal)
.SetNodeReuse(false));
};
foreach(var package in packageWhitelist)
{
build("./src/" + package + "/" + package + ".csproj", package);
}
build("./src/ReactiveUI.Tests/ReactiveUI.Tests.csproj", "ReactiveUI.Tests");
});
Task("RunUnitTests")
.IsDependentOn("BuildReactiveUI")
.Does(() =>
{
Action<ICakeContext> testAction = tool => {
tool.XUnit2("./src/ReactiveUI.Tests/bin/**/*.Tests.dll", new XUnit2Settings {
OutputDirectory = artifactDirectory,
XmlReport = true,
NoAppDomain = true
});
};
OpenCover(testAction,
testCoverageOutputFile,
new OpenCoverSettings {
ReturnTargetCodeOffset = 0,
ArgumentCustomization = args => args.Append("-mergeoutput")
}
.WithFilter("+[*]*")
.WithFilter("-[*.Testing]*")
.WithFilter("-[*.Tests*]*")
.WithFilter("-[Playground*]*")
.WithFilter("-[ReactiveUI.Events]*")
.WithFilter("-[Splat*]*")
.WithFilter("-[ApprovalTests*]*")
.ExcludeByAttribute("*.ExcludeFromCodeCoverage*")
.ExcludeByFile("*/*Designer.cs")
.ExcludeByFile("*/*.g.cs")
.ExcludeByFile("*/*.g.i.cs")
.ExcludeByFile("*splat/splat*")
.ExcludeByFile("*ApprovalTests*"));
ReportGenerator(testCoverageOutputFile, artifactDirectory);
}).ReportError(exception =>
{
var apiApprovals = GetFiles("./**/ApiApprovalTests.*");
CopyFiles(apiApprovals, artifactDirectory);
});
Task("UploadTestCoverage")
.WithCriteria(() => !local)
.WithCriteria(() => isRepository)
.IsDependentOn("RunUnitTests")
.Does(() =>
{
// Resolve the API key.
var token = EnvironmentVariable("COVERALLS_TOKEN");
if (string.IsNullOrEmpty(token))
{
throw new Exception("The COVERALLS_TOKEN environment variable is not defined.");
}
CoverallsIo(testCoverageOutputFile, new CoverallsIoSettings()
{
RepoToken = token
});
});
Task("SignPackages")
.WithCriteria(() => !local)
.WithCriteria(() => !isPullRequest)
.Does(() =>
{
StartPowershellFile("./SignPackages.ps1", args =>
{
});
});
Task("Package")
.IsDependentOn("BuildReactiveUI")
.IsDependentOn("RunUnitTests")
.IsDependentOn("UploadTestCoverage")
.IsDependentOn("PinNuGetDependencies")
.IsDependentOn("SignPackages")
.Does (() =>
{
});
Task("PinNuGetDependencies")
.Does (() =>
{
// only pin whitelisted packages.
foreach(var package in packageWhitelist)
{
// only pin the package which was created during this build run.
var packagePath = artifactDirectory + File(string.Concat(package, ".", nugetVersion, ".nupkg"));
// see https://github.com/cake-contrib/Cake.PinNuGetDependency
PinNuGetDependency(packagePath, "ReactiveUI");
}
});
Task("PublishPackages")
.IsDependentOn("RunUnitTests")
.IsDependentOn("Package")
.IsDependentOn("SignPackages")
.WithCriteria(() => !local)
.WithCriteria(() => !isPullRequest)
.WithCriteria(() => isRepository)
.WithCriteria(() => isDevelopBranch || isReleaseBranch)
.Does (() =>
{
if (isReleaseBranch && !isTagged)
{
Information("Packages will not be published as this release has not been tagged.");
return;
}
// Resolve the API key.
var apiKey = EnvironmentVariable("NUGET_APIKEY");
if (string.IsNullOrEmpty(apiKey))
{
throw new Exception("The NUGET_APIKEY environment variable is not defined.");
}
var source = EnvironmentVariable("NUGET_SOURCE");
if (string.IsNullOrEmpty(source))
{
throw new Exception("The NUGET_SOURCE environment variable is not defined.");
}
// only push whitelisted packages.
foreach(var package in packageWhitelist)
{
// only push the package which was created during this build run.
var packagePath = artifactDirectory + File(string.Concat(package, ".", nugetVersion, ".nupkg"));
// Push the package.
NuGetPush(packagePath, new NuGetPushSettings {
Source = source,
ApiKey = apiKey
});
}
});
Task("CreateRelease")
.IsDependentOn("Package")
.WithCriteria(() => !local)
.WithCriteria(() => !isPullRequest)
.WithCriteria(() => isRepository)
.WithCriteria(() => isReleaseBranch)
.WithCriteria(() => !isTagged)
.Does (() =>
{
var username = EnvironmentVariable("GITHUB_USERNAME");
if (string.IsNullOrEmpty(username))
{
throw new Exception("The GITHUB_USERNAME environment variable is not defined.");
}
var token = EnvironmentVariable("GITHUB_TOKEN");
if (string.IsNullOrEmpty(token))
{
throw new Exception("The GITHUB_TOKEN environment variable is not defined.");
}
GitReleaseManagerCreate(username, token, githubOwner, githubRepository, new GitReleaseManagerCreateSettings {
Milestone = majorMinorPatch,
Name = majorMinorPatch,
Prerelease = true,
TargetCommitish = "master"
});
});
Task("PublishRelease")
.IsDependentOn("RunUnitTests")
.IsDependentOn("Package")
.WithCriteria(() => !local)
.WithCriteria(() => !isPullRequest)
.WithCriteria(() => isRepository)
.WithCriteria(() => isReleaseBranch)
.WithCriteria(() => isTagged)
.Does (() =>
{
var username = EnvironmentVariable("GITHUB_USERNAME");
if (string.IsNullOrEmpty(username))
{
throw new Exception("The GITHUB_USERNAME environment variable is not defined.");
}
var token = EnvironmentVariable("GITHUB_TOKEN");
if (string.IsNullOrEmpty(token))
{
throw new Exception("The GITHUB_TOKEN environment variable is not defined.");
}
// only push whitelisted packages.
foreach(var package in packageWhitelist)
{
// only push the package which was created during this build run.
var packagePath = artifactDirectory + File(string.Concat(package, ".", nugetVersion, ".nupkg"));
GitReleaseManagerAddAssets(username, token, githubOwner, githubRepository, majorMinorPatch, packagePath);
}
GitReleaseManagerClose(username, token, githubOwner, githubRepository, majorMinorPatch);
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("CreateRelease")
.IsDependentOn("PublishPackages")
.IsDependentOn("PublishRelease")
.Does (() =>
{
});
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);