forked from ThomasLebrun/XForms-Toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
293 lines (249 loc) · 8.95 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
///////////////////////////////////////////////////////////////////////////////
// Directives
///////////////////////////////////////////////////////////////////////////////
#l "tools/versionUtils.cake"
#l "tools/settingsUtils.cake"
///////////////////////////////////////////////////////////////////////////////
// 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 buildSettings = SettingsUtils.LoadSettings(Context, settingsFile);
var versionInfo = VersionUtils.LoadVersion(Context, buildSettings);
///////////////////////////////////////////////////////////////////////////////
// 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);
CleanDirectories(path + "/**/bin/" + configuration);
CleanDirectories(path + "/**/obj/" + configuration);
}
});
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");
}
});
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.Build.NugetConfigPath });
}
});
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(1)
.WithProperty("TreatWarningsAsErrors",buildSettings.Build.TreatWarningsAsErrors.ToString())
.WithTarget("Build")
.SetConfiguration(configuration));
}
});
Task("Package")
.Description("Packages all nuspec files into nupkg packages.")
.IsDependentOn("Build")
.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());
}
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 and we can skip the symbols pkg for now
if (!pkg.ToString().Contains(versionInfo.ToString()) || pkg.ToString().Contains("symbols")) {
Information("Skipping {0}", pkg);
continue;
}
Information("Publishing {0}", pkg);
if (buildSettings.NuGet.FeedApiKey != "VSTS" ) {
NuGetPush(pkg, new NuGetPushSettings {
Source = buildSettings.NuGet.FeedUrl,
ApiKey = buildSettings.NuGet.FeedApiKey,
ConfigFile = buildSettings.NuGet.NuGetConfig,
Verbosity = NuGetVerbosity.Detailed
});
} else {
NuGetPush(pkg, new NuGetPushSettings {
Source = buildSettings.NuGet.FeedUrl,
ConfigFile = buildSettings.NuGet.NuGetConfig,
Verbosity = NuGetVerbosity.Detailed
});
}
}
});
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")
.IsDependentOn("UpdateVersion")
.Does(() =>
{
var oldVer = versionInfo.ToString();
if (versionInfo.IsPreRelease) versionInfo.PreRelease++; else versionInfo.Build++;
Information("Incrementing Version {0} to {1}", oldVer, versionInfo.ToString());
});
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);