forked from mongodb/mongo-csharp-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
485 lines (432 loc) · 17.1 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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#addin nuget:?package=Cake.FileHelpers&version=4.0.1
#addin nuget:?package=Cake.Git&version=1.0.1
#addin nuget:?package=Cake.Incubator&version=6.0.0
#tool dotnet:?package=GitVersion.Tool&version=5.6.9
using System;
using System.Text.RegularExpressions;
using System.Linq;
using Cake.Common.Tools.DotNetCore.DotNetCoreVerbosity;
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var gitVersion = GitVersion();
var solutionDirectory = MakeAbsolute(Directory("./"));
var artifactsDirectory = solutionDirectory.Combine("artifacts");
var artifactsBinDirectory = artifactsDirectory.Combine("bin");
var artifactsDocsDirectory = artifactsDirectory.Combine("docs");
var artifactsDocsApiDocsDirectory = artifactsDocsDirectory.Combine("ApiDocs-" + gitVersion.LegacySemVer);
var artifactsDocsRefDocsDirectory = artifactsDocsDirectory.Combine("RefDocs-" + gitVersion.LegacySemVer);
var artifactsPackagesDirectory = artifactsDirectory.Combine("packages");
var docsDirectory = solutionDirectory.Combine("Docs");
var docsApiDirectory = docsDirectory.Combine("Api");
var srcDirectory = solutionDirectory.Combine("src");
var testsDirectory = solutionDirectory.Combine("tests");
var toolsDirectory = solutionDirectory.Combine("tools");
var toolsHugoDirectory = toolsDirectory.Combine("Hugo");
var solutionFile = solutionDirectory.CombineWithFilePath("CSharpDriver.sln");
var solutionFullPath = solutionFile.FullPath;
var srcProjectNames = new[]
{
"MongoDB.Bson",
"MongoDB.Driver.Core",
"MongoDB.Driver",
"MongoDB.Driver.Legacy",
"MongoDB.Driver.GridFS"
};
Task("Default")
.IsDependentOn("Test");
Task("Release")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Docs")
.IsDependentOn("Package");
Task("Restore")
.Does(() =>
{
// disable parallel restore to work around apparent bugs in restore
var restoreSettings = new DotNetCoreRestoreSettings
{
DisableParallel = true
};
DotNetCoreRestore(solutionFullPath, restoreSettings);
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
var settings = new DotNetCoreBuildSettings
{
NoRestore = true,
Configuration = configuration,
EnvironmentVariables = new Dictionary<string, string>
{
{ "Version", gitVersion.LegacySemVer },
{ "SourceRevisionId", gitVersion.Sha }
}
};
DotNetCoreBuild(solutionFullPath, settings);
});
Task("BuildArtifacts")
.IsDependentOn("Build")
.Does(() =>
{
foreach (var targetFramework in new[] { "net452", "netstandard1.5", "netstandard2.0", "netstandard2.1" })
{
var toDirectory = artifactsBinDirectory.Combine(targetFramework);
CleanDirectory(toDirectory);
var projects = new[] { "MongoDB.Bson", "MongoDB.Driver.Core", "MongoDB.Driver", "MongoDB.Driver.Legacy", "MongoDB.Driver.GridFS" };
foreach (var project in projects)
{
var fromDirectory = srcDirectory.Combine(project).Combine("bin").Combine(configuration).Combine(targetFramework);
var fileNames = new List<string>();
foreach (var extension in new[] { "dll", "pdb", "xml" })
{
var fileName = $"{project}.{extension}";
fileNames.Add(fileName);
}
// add additional files needed by Sandcastle
if (targetFramework == "net452" && project == "MongoDB.Driver.Core")
{
fileNames.Add("DnsClient.dll");
fileNames.Add("MongoDB.Libmongocrypt.dll");
fileNames.Add("SharpCompress.dll");
}
foreach (var fileName in fileNames)
{
var fromFile = fromDirectory.CombineWithFilePath(fileName);
var toFile = toDirectory.CombineWithFilePath(fileName);
CopyFile(fromFile, toFile);
}
}
}
});
Task("Test")
.IsDependentOn("Build")
.DoesForEach(
GetFiles("./**/*.Tests.csproj")
.Where(name => !name.ToString().Contains("Atlas")),
testProject =>
{
var testWithDefaultGuidRepresentationMode = Environment.GetEnvironmentVariable("TEST_WITH_DEFAULT_GUID_REPRESENTATION_MODE");
if (testWithDefaultGuidRepresentationMode != null)
{
Console.WriteLine($"TEST_WITH_DEFAULT_GUID_REPRESENTATION_MODE={testWithDefaultGuidRepresentationMode}");
}
var testWithDefaultGuidRepresentation = Environment.GetEnvironmentVariable("TEST_WITH_DEFAULT_GUID_REPRESENTATION");
if (testWithDefaultGuidRepresentation != null)
{
Console.WriteLine($"TEST_WITH_DEFAULT_GUID_REPRESENTATION={testWithDefaultGuidRepresentation}");
}
var mongoX509ClientCertificatePath = Environment.GetEnvironmentVariable("MONGO_X509_CLIENT_CERTIFICATE_PATH");
if (mongoX509ClientCertificatePath != null)
{
Console.WriteLine($"MONGO_X509_CLIENT_CERTIFICATE_PATH={mongoX509ClientCertificatePath}");
}
var mongoX509ClientCertificatePassword = Environment.GetEnvironmentVariable("MONGO_X509_CLIENT_CERTIFICATE_PASSWORD");
if (mongoX509ClientCertificatePassword != null)
{
Console.WriteLine($"MONGO_X509_CLIENT_CERTIFICATE_PASSWORD={mongoX509ClientCertificatePassword}");
}
var settings = new DotNetCoreTestSettings
{
NoBuild = true,
NoRestore = true,
Configuration = configuration,
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64")
};
switch (target.ToLowerInvariant())
{
case "testnet452": settings.Framework = "net452"; break;
case "testnetstandard15": settings.Framework = "netcoreapp1.1"; break;
case "testnetstandard20": settings.Framework = "netcoreapp2.1"; break;
case "testnetstandard21": settings.Framework = "netcoreapp3.0"; break;
}
DotNetCoreTest(
testProject.FullPath,
settings
);
})
.DeferOnError();
Task("TestNet452").IsDependentOn("Test");
Task("TestNetStandard15").IsDependentOn("Test");
Task("TestNetStandard20").IsDependentOn("Test");
Task("TestNetStandard21").IsDependentOn("Test");
Task("TestAwsAuthentication")
.IsDependentOn("Build")
.DoesForEach(
GetFiles("./**/MongoDB.Driver.Tests.csproj"),
testProject =>
{
DotNetCoreTest(
testProject.FullPath,
new DotNetCoreTestSettings {
NoBuild = true,
NoRestore = true,
Configuration = configuration,
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64"),
Filter = "Category=\"AwsMechanism\""
}
);
});
Task("TestPlainAuthentication")
.IsDependentOn("Build")
.DoesForEach(
GetFiles("./**/MongoDB.Driver.Tests.csproj"),
testProject =>
{
DotNetCoreTest(
testProject.FullPath,
new DotNetCoreTestSettings {
NoBuild = true,
NoRestore = true,
Configuration = configuration,
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64"),
Filter = "Category=\"PlainMechanism\""
}
);
});
// currently we are not running this Task on Evergreen (only locally occassionally)
Task("TestAllGuidRepresentations")
.IsDependentOn("Build")
.DoesForEach(
GetFiles("./**/*.Tests.csproj")
// .Where(name => name.ToString().Contains("Bson.Tests")) // uncomment to only test Bson
.Where(name => !name.ToString().Contains("Atlas")),
testProject =>
{
var modes = new string[][]
{
new[] { "V2", "Unspecified" },
new[] { "V2", "JavaLegacy" },
new[] { "V2", "Standard" },
new[] { "V2", "PythonLegacy" },
new[] { "V2", "CSharpLegacy" },
new[] { "V3", "Unspecified" }
};
foreach (var mode in modes)
{
var testWithGuidRepresentationMode = mode[0];
var testWithGuidRepresentation = mode[1];
Console.WriteLine($"TEST_WITH_DEFAULT_GUID_REPRESENTATION_MODE={testWithGuidRepresentationMode}");
Console.WriteLine($"TEST_WITH_DEFAULT_GUID_REPRESENTATION={testWithGuidRepresentation}");
DotNetCoreTest(
testProject.FullPath,
new DotNetCoreTestSettings {
NoBuild = true,
NoRestore = true,
Configuration = configuration,
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64"),
EnvironmentVariables = new Dictionary<string, string>
{
{ "TEST_WITH_DEFAULT_GUID_REPRESENTATION_MODE", testWithGuidRepresentationMode },
{ "TEST_WITH_DEFAULT_GUID_REPRESENTATION", testWithGuidRepresentation }
}
}
);
}
});
Task("TestAtlasConnectivity")
.IsDependentOn("Build")
.DoesForEach(
GetFiles("./**/AtlasConnectivity.Tests.csproj"),
testProject =>
{
DotNetCoreTest(
testProject.FullPath,
new DotNetCoreTestSettings {
NoBuild = true,
NoRestore = true,
Configuration = configuration,
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64")
}
);
});
Task("TestAtlasDataLake")
.IsDependentOn("Build")
.DoesForEach(
GetFiles("./**/MongoDB.Driver.Tests.csproj"),
testProject =>
{
DotNetCoreTest(
testProject.FullPath,
new DotNetCoreTestSettings {
NoBuild = true,
NoRestore = true,
Configuration = configuration,
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64"),
Filter = "Category=\"AtlasDataLake\""
}
);
});
Task("TestOcsp")
.IsDependentOn("Build")
.DoesForEach(
GetFiles("./**/MongoDB.Driver.Tests.csproj"),
testProject =>
{
DotNetCoreTest(
testProject.FullPath,
new DotNetCoreTestSettings {
NoBuild = true,
NoRestore = true,
Configuration = configuration,
ArgumentCustomization = args => args
.Append("--filter FullyQualifiedName~OcspIntegrationTests")
.Append("-- RunConfiguration.TargetPlatform=x64")
}
);
});
Task("TestGssapi")
.IsDependentOn("Build")
.DoesForEach(
GetFiles("./**/MongoDB.Driver.Tests.csproj"),
testProject =>
{
var settings = new DotNetCoreTestSettings
{
NoBuild = true,
NoRestore = true,
Configuration = configuration,
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64"),
Filter = "Category=\"GssapiMechanism\""
};
switch (target.ToLowerInvariant())
{
case "testgssapinet452": settings.Framework = "net452"; break;
case "testgssapinetstandard15": settings.Framework = "netcoreapp1.1"; break;
case "testgssapinetstandard20": settings.Framework = "netcoreapp2.1"; break;
case "testgssapinetstandard21": settings.Framework = "netcoreapp3.0"; break;
}
DotNetCoreTest(
testProject.FullPath,
settings
);
});
Task("TestGssapiNet452").IsDependentOn("TestGssapi");
Task("TestGssapiNetStandard15").IsDependentOn("TestGssapi");
Task("TestGssapiNetStandard20").IsDependentOn("TestGssapi");
Task("TestGssapiNetStandard21").IsDependentOn("TestGssapi");
Task("Docs")
.IsDependentOn("ApiDocs")
.IsDependentOn("RefDocs");
Task("ApiDocs")
.IsDependentOn("BuildArtifacts")
.Does(() =>
{
EnsureDirectoryExists(artifactsDocsApiDocsDirectory);
CleanDirectory(artifactsDocsApiDocsDirectory);
var shfbprojFile = docsApiDirectory.CombineWithFilePath("CSharpDriverDocs.shfbproj");
var preliminary = false; // TODO: compute
MSBuild(shfbprojFile, new MSBuildSettings
{
Configuration = "Release"
}
.WithProperty("OutputPath", artifactsDocsApiDocsDirectory.ToString())
.WithProperty("CleanIntermediate", "True")
.WithProperty("Preliminary", preliminary ? "True" : "False")
.WithProperty("HelpFileVersion", gitVersion.LegacySemVer)
);
var lowerCaseIndexFile = artifactsDocsApiDocsDirectory.CombineWithFilePath("index.html");
var upperCaseIndexFile = artifactsDocsApiDocsDirectory.CombineWithFilePath("Index.html");
MoveFile(upperCaseIndexFile, lowerCaseIndexFile);
var chmFile = artifactsDocsApiDocsDirectory.CombineWithFilePath("CSharpDriverDocs.chm");
var artifactsDocsChmFile = artifactsDocsDirectory.CombineWithFilePath("CSharpDriverDocs.chm");
CopyFile(chmFile, artifactsDocsChmFile);
});
Task("RefDocs")
.Does(() =>
{
EnsureDirectoryExists(toolsHugoDirectory);
CleanDirectory(toolsHugoDirectory);
var url = "https://github.com/spf13/hugo/releases/download/v0.13/hugo_0.13_windows_amd64.zip";
var hugoZipFile = toolsHugoDirectory.CombineWithFilePath("hugo_0.13_windows_amd64.zip");
DownloadFile(url, hugoZipFile);
Unzip(hugoZipFile, toolsHugoDirectory);
var hugoExe = toolsHugoDirectory.CombineWithFilePath("hugo_0.13_windows_amd64.exe");
var landingDirectory = docsDirectory.Combine("landing");
var landingPublicDirectory = landingDirectory.Combine("public");
CleanDirectory(landingPublicDirectory);
var processSettings = new ProcessSettings
{
WorkingDirectory = landingDirectory
};
StartProcess(hugoExe, processSettings);
var referenceDirectory = docsDirectory.Combine("reference");
var referencePublicDirectory = referenceDirectory.Combine("public");
CleanDirectory(referencePublicDirectory);
processSettings = new ProcessSettings
{
WorkingDirectory = referenceDirectory
};
StartProcess(hugoExe, processSettings);
EnsureDirectoryExists(artifactsDocsRefDocsDirectory);
CleanDirectory(artifactsDocsRefDocsDirectory);
CopyDirectory(landingPublicDirectory, artifactsDocsRefDocsDirectory);
var artifactsReferencePublicDirectory = artifactsDocsRefDocsDirectory.Combine(gitVersion.Major + "." + gitVersion.Minor);
CopyDirectory(referencePublicDirectory, artifactsReferencePublicDirectory);
});
Task("Package")
.IsDependentOn("PackageNugetPackages");
Task("PackageNugetPackages")
.IsDependentOn("Build")
.Does(() =>
{
EnsureDirectoryExists(artifactsPackagesDirectory);
CleanDirectory(artifactsPackagesDirectory);
var projects = new[]
{
"MongoDB.Bson",
"MongoDB.Driver.Core",
"MongoDB.Driver",
"MongoDB.Driver.GridFS",
"MongoDB.Driver.Legacy"
};
foreach (var project in projects)
{
var projectPath = $"{srcDirectory}\\{project}\\{project}.csproj";
var settings = new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = artifactsPackagesDirectory,
NoBuild = true,
IncludeSymbols = true,
MSBuildSettings = new DotNetCoreMSBuildSettings()
.WithProperty("PackageVersion", gitVersion.LegacySemVer)
};
DotNetCorePack(projectPath, settings);
}
});
Task("PushToNuGet")
.Does(() =>
{
var nugetApiKey = EnvironmentVariable("NUGETAPIKEY");
if (nugetApiKey == null)
{
throw new Exception("NUGETAPIKEY environment variable missing");
}
var packageFiles = new List<FilePath>();
var projects = new[]
{
"MongoDB.Bson",
"MongoDB.Driver.Core",
"MongoDB.Driver",
"MongoDB.Driver.GridFS",
"mongocsharpdriver" // the Nuget package name for MongoDB.Driver.Legacy
};
foreach (var project in projects)
{
var packageFileName = $"{project}.{gitVersion.LegacySemVer}.nupkg";
var packageFile = artifactsPackagesDirectory.CombineWithFilePath(packageFileName);
packageFiles.Add(packageFile);
}
NuGetPush(packageFiles, new NuGetPushSettings
{
ApiKey = nugetApiKey,
Source = "https://api.nuget.org/v3/index.json"
});
});
Task("DumpGitVersion")
.Does(() =>
{
Information(gitVersion.Dump());
});
RunTarget(target);