forked from eventflow/EventFlow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.cake
333 lines (287 loc) · 9.97 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
// The MIT License (MIT)
//
// Copyright (c) 2015-2017 Rasmus Mikkelsen
// Copyright (c) 2015-2017 eBay Software Foundation
// https://github.com/eventflow/EventFlow
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#r "System.IO.Compression.FileSystem"
#r "System.Xml"
#tool "nuget:?package=NUnit.ConsoleRunner"
#tool "nuget:?package=OpenCover"
using System.IO.Compression;
using System.Net;
using System.Xml;
var VERSION = GetArgumentVersion();
var PROJECT_DIR = Context.Environment.WorkingDirectory.FullPath;
var CONFIGURATION = "Release";
// IMPORTANT DIRECTORIES
var DIR_OUTPUT_PACKAGES = System.IO.Path.Combine(PROJECT_DIR, "Build", "Packages");
var DIR_OUTPUT_REPORTS = System.IO.Path.Combine(PROJECT_DIR, "Build", "Reports");
// IMPORTANT FILES
var FILE_OPENCOVER_REPORT = System.IO.Path.Combine(DIR_OUTPUT_REPORTS, "opencover-results.xml");
var FILE_NUNIT_XML_REPORT = System.IO.Path.Combine(DIR_OUTPUT_REPORTS, "nunit-results.xml");
var FILE_NUNIT_TXT_REPORT = System.IO.Path.Combine(DIR_OUTPUT_REPORTS, "nunit-output.txt");
var FILE_SOLUTION = System.IO.Path.Combine(PROJECT_DIR, "EventFlow.sln");
var RELEASE_NOTES = ParseReleaseNotes(System.IO.Path.Combine(PROJECT_DIR, "RELEASE_NOTES.md"));
// =====================================================================================================
Task("Default")
.IsDependentOn("Package");
// =====================================================================================================
Task("Clean")
.Does(() =>
{
CleanDirectories(new []
{
DIR_OUTPUT_PACKAGES,
DIR_OUTPUT_REPORTS,
});
DeleteDirectories(GetDirectories("**/bin"), true);
DeleteDirectories(GetDirectories("**/obj"), true);
});
// =====================================================================================================
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore(
".",
new DotNetCoreRestoreSettings()
{
ArgumentCustomization = aggs => aggs.Append(GetDotNetCoreArgsVersions())
});
});
// =====================================================================================================
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetCoreBuild(
".",
new DotNetCoreBuildSettings()
{
Configuration = CONFIGURATION,
ArgumentCustomization = aggs => aggs
.Append(GetDotNetCoreArgsVersions())
.Append("/p:ci=true")
.Append("/p:SourceLinkEnabled=true")
});
});
// =====================================================================================================
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
ExecuteTest("./Source/**/bin/" + CONFIGURATION + "/**/EventFlow*Tests.dll", FILE_NUNIT_XML_REPORT);
})
.Finally(() =>
{
UploadArtifact(FILE_NUNIT_TXT_REPORT);
UploadTestResults(FILE_NUNIT_XML_REPORT);
});
// =====================================================================================================
Task("Package")
.IsDependentOn("Test")
.Does(() =>
{
Information("Version: {0}", RELEASE_NOTES.Version);
Information(string.Join(Environment.NewLine, RELEASE_NOTES.Notes));
foreach (var project in GetFiles("./Source/**/*.csproj"))
{
var name = project.GetDirectory().FullPath;
var version = VERSION.ToString();
if ((name.Contains("Test") && !name.Contains("TestHelpers")) || name.Contains("Example"))
{
continue;
}
SetReleaseNotes(project.ToString());
DotNetCorePack(
name,
new DotNetCorePackSettings
{
Configuration = CONFIGURATION,
OutputDirectory = DIR_OUTPUT_PACKAGES,
NoBuild = true,
Verbosity = DotNetCoreVerbosity.Detailed,
ArgumentCustomization = aggs => aggs.Append(GetDotNetCoreArgsVersions())
});
}
});
// =====================================================================================================
Task("All")
.IsDependentOn("Package")
.Does(() =>
{
});
// =====================================================================================================
Version GetArgumentVersion()
{
return Version.Parse(EnvironmentVariable("APPVEYOR_BUILD_VERSION") ?? "0.0.1");
}
string GetDotNetCoreArgsVersions()
{
var version = GetArgumentVersion().ToString();
return string.Format(
@"/p:Version={0} /p:AssemblyVersion={0} /p:FileVersion={0} /p:ProductVersion={0}",
version);
}
void SetReleaseNotes(string filePath)
{
var releaseNotes = string.Join(Environment.NewLine, RELEASE_NOTES.Notes);
var xmlDocument = new XmlDocument();
xmlDocument.Load(filePath);
var node = xmlDocument.SelectSingleNode("Project/PropertyGroup/PackageReleaseNotes") as XmlElement;
if (node == null)
{
throw new Exception(string.Format(
"Project {0} does not have a `<PackageReleaseNotes>UPDATED BY BUILD</PackageReleaseNotes>` property",
filePath));
}
if (!AppVeyor.IsRunningOnAppVeyor)
{
Information("Skipping update of release notes");
return;
}
else
{
Information(string.Format("Setting release notes in '{0}'", filePath));
node.InnerText = releaseNotes;
xmlDocument.Save(filePath);
}
}
void UploadArtifact(string filePath)
{
if (!FileExists(filePath))
{
Information("Skipping uploading of artifact, does not exist: {0}", filePath);
return;
}
if (AppVeyor.IsRunningOnAppVeyor)
{
Information("Uploading artifact: {0}", filePath);
AppVeyor.UploadArtifact(filePath);
}
else
{
Information("Not on AppVeyor, skipping artifact upload of: {0}", filePath);
}
}
void UploadTestResults(string filePath)
{
if (!FileExists(filePath))
{
Information("Skipping uploading of test results, does not exist: {0}", filePath);
return;
}
if (AppVeyor.IsRunningOnAppVeyor)
{
Information("Uploading test results: {0}", filePath);
try
{
using (var webClient = new WebClient())
{
webClient.UploadFile(
string.Format(
"https://ci.appveyor.com/api/testresults/nunit3/{0}",
Environment.GetEnvironmentVariable("APPVEYOR_JOB_ID")),
filePath);
}
}
catch (Exception e)
{
Error(
"Failed to upload '{0}' due to {1} - {2}: {3}",
filePath,
e.Message,
e.GetType().Name,
e.ToString());
}
/*
// This should work, but doesn't seem to
AppVeyor.UploadTestResults(
filePath,
AppVeyorTestResultsType.NUnit3);*/
}
else
{
Information("Not on AppVeyor, skipping test result upload of: {0}", filePath);
}
}
string ExecuteCommand(string exePath, string arguments = null, string workingDirectory = null)
{
Information("Executing '{0}' {1}", exePath, arguments ?? string.Empty);
using (var process = new System.Diagnostics.Process())
{
process.StartInfo = new System.Diagnostics.ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardOutput = true,
FileName = exePath,
Arguments = arguments,
WorkingDirectory = workingDirectory,
};
process.Start();
var output = process.StandardOutput.ReadToEnd();
if (!process.WaitForExit(30000))
{
throw new Exception("Failed to stop process!");
}
Debug(output);
if (process.ExitCode != 0)
{
throw new Exception(string.Format("Error code {0} was returned", process.ExitCode));
}
return output;
}
}
void ExecuteTest(string files, string resultsFile)
{
OpenCover(tool =>
{
tool.NUnit3(
files,
new NUnit3Settings
{
Framework = "net-4.5",
Timeout = 600000,
ShadowCopy = false,
NoHeader = true,
NoColor = true,
DisposeRunners = true,
OutputFile = FILE_NUNIT_TXT_REPORT,
Results = new []
{
new NUnit3Result
{
FileName = resultsFile,
}
}
});
},
new FilePath(FILE_OPENCOVER_REPORT),
new OpenCoverSettings
{
ArgumentCustomization = aggs => aggs.Append("-returntargetcode")
}
.WithFilter("+[EventFlow*]*")
.WithFilter("-[*Tests]*")
.WithFilter("-[*TestHelpers]*")
.WithFilter("-[*Shipping*]*"));
}
RunTarget(Argument<string>("target", "Package"));