forked from igrali/portable-exif-lib
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.cake
349 lines (294 loc) · 10.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
///////////////////////////////////////////////////////////////////////////////
// Directives
///////////////////////////////////////////////////////////////////////////////
#l "tools/versionUtils.cake"
#l "tools/settingsUtils.cake"
#tool "nuget:?package=NUnit.ConsoleRunner"
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
var settingsFile = Argument<string>("settingsFile", ".\\settings.json");
var skipBuild = Argument<string>("skipBuild", "false").ToLower() == "true" || Argument<string>("skipBuild", "false") == "1";
var skipPackage = Argument<string>("skipPackage", "false").ToLower() == "true" || Argument<string>("skipPackage", "false") == "1";
var buildSettings = SettingsUtils.LoadSettings(Context, settingsFile);
var versionInfo = VersionUtils.LoadVersion(Context, buildSettings);
// Allow for any overrides
buildSettings.NuGet.LibraryMinVersionDependency = (Argument<string>("dependencyVersion", buildSettings.NuGet.LibraryMinVersionDependency)).Replace(":",".");
buildSettings.NuGet.VersionDependencyTypeForLibrary = Argument<VersionDependencyTypes>("dependencyType", buildSettings.NuGet.VersionDependencyTypeForLibrary);
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var solutions = GetFiles(buildSettings.Build.SolutionFilePath);
var solutionPaths = solutions.Select(solution => solution.GetDirectory());
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup((c) =>
{
c.Information("Command Line:");
c.Information("\tConfiguration: {0}", configuration);
c.Information("\tSettings Files: {0}", settingsFile);
c.Information("\tSkip Build: {0}", skipBuild);
c.Information("\tSolutions Found: {0}", solutions.Count);
// Executed BEFORE the first task.
buildSettings.Display(c);
versionInfo.Display(c);
});
Teardown((c) =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Description("Cleans all directories that are used during the build process.")
.WithCriteria(!skipBuild)
.Does(() =>
{
// Clean solution directories.
foreach(var path in solutionPaths)
{
Information("Cleaning {0}", path);
try { CleanDirectories(path + "/**/bin/" + configuration); } catch {}
try { CleanDirectories(path + "/**/obj/" + configuration); } catch {}
}
var pathTest = MakeAbsolute(Directory(buildSettings.Test.SourcePath)).FullPath;
Information("Cleaning {0}", pathTest);
try { CleanDirectories(pathTest + "/**/bin/" + configuration); } catch {}
try { CleanDirectories(pathTest + "/**/obj/" + configuration); } catch {}
});
Task("CleanAll")
.Description("Cleans all directories that are used during the build process.")
.Does(() =>
{
// Clean solution directories.
foreach(var path in solutionPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/**/bin");
CleanDirectories(path + "/**/obj");
CleanDirectories(path + "/packages/**/*");
CleanDirectories(path + "/artifacts/**/*");
CleanDirectories(path + "/packages");
CleanDirectories(path + "/artifacts");
}
var pathTest = MakeAbsolute(Directory(buildSettings.Test.SourcePath)).FullPath;
Information("Cleaning {0}", pathTest);
try { CleanDirectories(pathTest + "/**/bin"); } catch {}
try { CleanDirectories(pathTest + "/**/obj"); } catch {}
});
Task("CleanPackages")
.Description("Cleans all packages that are used during the build process.")
.Does(() =>
{
// Clean solution directories.
foreach(var path in solutionPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/packages/**/*");
CleanDirectories(path + "/packages");
}
});
Task("Restore")
.Description("Restores all the NuGet packages that are used by the specified solution.")
.WithCriteria(!skipBuild)
.Does(() =>
{
// Restore all NuGet packages.
foreach(var solution in solutions)
{
Information("Restoring {0}...", solution);
NuGetRestore(solution, new NuGetRestoreSettings { ConfigFile = buildSettings.NuGet.NuGetConfig });
}
});
Task("Build")
.Description("Builds all the different parts of the project.")
.WithCriteria(!skipBuild)
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("UpdateVersion")
.Does(() =>
{
if (buildSettings.Version.AutoIncrementVersion)
{
RunTarget("IncrementVersion");
}
// Build all solutions.
foreach(var solution in solutions)
{
Information("Building {0}", solution);
MSBuild(solution, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
.SetMaxCpuCount(buildSettings.Build.MaxCpuCount)
.WithProperty("TreatWarningsAsErrors",buildSettings.Build.TreatWarningsAsErrors.ToString())
.WithTarget("Build")
.SetConfiguration(configuration));
}
});
Task("UnitTest")
.Description("Run unit tests for the solution.")
.WithCriteria(!skipBuild)
.IsDependentOn("Build")
.Does(() =>
{
// Run all unit tests we can find.
var assemplyFilePath = string.Format("{0}/**/bin/{1}/{2}", buildSettings.Test.SourcePath, configuration, buildSettings.Test.AssemblyFileSpec);
Information("Unit Test Files: {0}", assemplyFilePath);
var unitTestAssemblies = GetFiles(assemplyFilePath);
foreach(var uta in unitTestAssemblies)
{
Information("Executing Tests for {0}", uta);
switch (buildSettings.Test.Framework)
{
case TestFrameworkTypes.NUnit2:
NUnit(uta.ToString(), new NUnitSettings { });
break;
case TestFrameworkTypes.NUnit3:
NUnit3(uta.ToString(), new NUnit3Settings { Configuration=configuration });
break;
case TestFrameworkTypes.XUnit:
XUnit(uta.ToString(), new XUnitSettings { OutputDirectory = buildSettings.Test.ResultsPath });
break;
case TestFrameworkTypes.XUnit2:
XUnit2(uta.ToString(), new XUnit2Settings { OutputDirectory = buildSettings.Test.ResultsPath, XmlReportV1 = true });
break;
}
}
});
Task("Package")
.Description("Packages all nuspec files into nupkg packages.")
.WithCriteria(!skipPackage)
.IsDependentOn("UnitTest")
.Does(() =>
{
var artifactsPath = Directory(buildSettings.NuGet.ArtifactsPath);
var nugetProps = new Dictionary<string, string>() { {"Configuration", configuration} };
CreateDirectory(artifactsPath);
var nuspecFiles = GetFiles(buildSettings.NuGet.NuSpecFileSpec);
foreach(var nsf in nuspecFiles)
{
Information("Packaging {0}", nsf);
if (buildSettings.NuGet.UpdateVersion) {
VersionUtils.UpdateNuSpecVersion(Context, buildSettings, versionInfo, nsf.ToString());
}
if (buildSettings.NuGet.UpdateLibraryDependencies) {
VersionUtils.UpdateNuSpecVersionDependency(Context, buildSettings, versionInfo, nsf.ToString());
}
NuGetPack(nsf, new NuGetPackSettings {
Version = versionInfo.ToString(),
ReleaseNotes = versionInfo.ReleaseNotes,
Symbols = true,
Properties = nugetProps,
OutputDirectory = artifactsPath
});
}
});
Task("Publish")
.Description("Publishes all of the nupkg packages to the nuget server. ")
.IsDependentOn("Package")
.Does(() =>
{
var nupkgFiles = GetFiles(buildSettings.NuGet.NuGetPackagesSpec);
foreach(var pkg in nupkgFiles)
{
// Lets skip everything except the current version
if (!pkg.ToString().Contains(versionInfo.ToString())) {
Information("Skipping {0}", pkg);
continue;
}
Information("Publishing {0}", pkg);
try
{
NuGetPush(pkg, new NuGetPushSettings {
Source = buildSettings.NuGet.FeedUrl,
ApiKey = buildSettings.NuGet.FeedApiKey,
ConfigFile = buildSettings.NuGet.NuGetConfig,
Verbosity = NuGetVerbosity.Normal
});
}
catch (Exception ex)
{
Information("\tFailed to published: ", ex.Message);
}
}
});
Task("UnPublish")
.Description("UnPublishes all of the current nupkg packages from the nuget server. Issue: versionToDelete must use : instead of . due to bug in cake")
.Does(() =>
{
var v = Argument<string>("versionToDelete", versionInfo.ToString()).Replace(":",".");
var nuspecFiles = GetFiles(buildSettings.NuGet.NuSpecFileSpec);
foreach(var f in nuspecFiles)
{
Information("UnPublishing {0}", f.GetFilenameWithoutExtension());
var args = string.Format("delete {0} {1} -Source {2} -NonInteractive",
f.GetFilenameWithoutExtension(),
v,
buildSettings.NuGet.FeedUrl
);
//if (buildSettings.NuGet.FeedApiKey != "VSTS" ) {
args = args + string.Format(" -ApiKey {0}", buildSettings.NuGet.FeedApiKey);
//}
if (!string.IsNullOrEmpty(buildSettings.NuGet.NuGetConfig)) {
args = args + string.Format(" -Config {0}", buildSettings.NuGet.NuGetConfig);
}
Information("NuGet Command Line: {0}", args);
using (var process = StartAndReturnProcess("tools\\nuget.exe", new ProcessSettings {
Arguments = args
}))
{
process.WaitForExit();
Information("nuget delete exit code: {0}", process.GetExitCode());
}
}
});
Task("UpdateVersion")
.Description("Updates the version number in the necessary files")
.Does(() =>
{
Information("Updating Version to {0}", versionInfo.ToString());
VersionUtils.UpdateVersion(Context, buildSettings, versionInfo);
});
Task("IncrementVersion")
.Description("Increments the version number and then updates it in the necessary files")
.Does(() =>
{
var oldVer = versionInfo.ToString();
if (versionInfo.IsPreRelease) versionInfo.PreRelease++; else versionInfo.Build++;
Information("Incrementing Version {0} to {1}", oldVer, versionInfo.ToString());
RunTarget("UpdateVersion");
});
Task("BuildNewVersion")
.Description("Increments and Builds a new version")
.IsDependentOn("IncrementVersion")
.IsDependentOn("Build")
.Does(() =>
{
});
Task("PublishNewVersion")
.Description("Increments, Builds, and publishes a new version")
.IsDependentOn("BuildNewVersion")
.IsDependentOn("Publish")
.Does(() =>
{
});
Task("DisplaySettings")
.Description("Displays All Settings.")
.Does(() =>
{
// Settings will be displayed as they are part of the Setup task
});
///////////////////////////////////////////////////////////////////////////////
// TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Default")
.Description("This is the default task which will be ran if no specific target is passed in.")
.IsDependentOn("Build");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);