forked from cake-build/cake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
393 lines (348 loc) · 12 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
// Install addins.
#addin "nuget:?package=Polly&version=4.2.0"
// Install tools.
#tool "nuget:?package=xunit.runner.console&version=2.1.0"
#tool "nuget:?package=gitreleasemanager&version=0.4.0"
#tool "nuget:?package=GitVersion.CommandLine&version=3.4.1"
// Load other scripts.
#load "./build/parameters.cake"
// Using statements
using Polly;
//////////////////////////////////////////////////////////////////////
// PARAMETERS
//////////////////////////////////////////////////////////////////////
BuildParameters parameters = BuildParameters.GetParameters(Context, BuildSystem);
bool publishingError = false;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
parameters.SetBuildVersion(
BuildVersion.CalculatingSemanticVersion(
context: Context,
parameters: parameters
)
);
parameters.SetBuildPaths(
BuildPaths.GetPaths(
context: Context,
configuration: parameters.Configuration,
semVersion: parameters.Version.SemVersion
)
);
parameters.SetBuildPackages(
BuildPackages.GetPackages(
nugetRooPath: parameters.Paths.Directories.NugetRoot,
semVersion: parameters.Version.SemVersion,
packageIds: new [] { "Cake", "Cake.Core", "Cake.Common", "Cake.Testing" },
chocolateyPackageIds: new [] { "cake.portable" }
)
);
Information("Building version {0} of Cake ({1}, {2}) using version {3} of Cake. (IsTagged: {4})",
parameters.Version.SemVersion,
parameters.Configuration,
parameters.Target,
parameters.Version.CakeVersion,
parameters.IsTagged);
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() => CleanDirectories(parameters.Paths.Directories.ToClean));
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
var maxRetryCount = 5;
var toolTimeout = 1d;
Policy
.Handle<Exception>()
.Retry(maxRetryCount, (exception, retryCount, context) => {
if (retryCount == maxRetryCount)
{
throw exception;
}
else
{
Verbose("{0}", exception);
toolTimeout+=0.5;
}})
.Execute(()=> {
NuGetRestore("./src/Cake.sln", new NuGetRestoreSettings {
Source = new List<string> {
"https://api.nuget.org/v3/index.json",
"https://www.myget.org/F/roslyn-nightly/api/v3/index.json"
},
ToolTimeout = TimeSpan.FromMinutes(toolTimeout)
});
});
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
if(parameters.IsRunningOnUnix)
{
XBuild("./src/Cake.sln", new XBuildSettings()
.SetConfiguration(parameters.Configuration)
.WithProperty("POSIX", "True")
.WithProperty("TreatWarningsAsErrors", "True")
.SetVerbosity(Verbosity.Minimal)
);
}
else
{
MSBuild("./src/Cake.sln", new MSBuildSettings()
.SetConfiguration(parameters.Configuration)
.WithProperty("Windows", "True")
.WithProperty("TreatWarningsAsErrors", "True")
.UseToolVersion(MSBuildToolVersion.NET45)
.SetVerbosity(Verbosity.Minimal)
.SetNodeReuse(false));
}
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
XUnit2("./src/**/bin/" + parameters.Configuration + "/*.Tests.dll", new XUnit2Settings {
OutputDirectory = parameters.Paths.Directories.TestResults,
XmlReportV1 = true,
NoAppDomain = true
});
});
Task("Copy-Files")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
CopyFiles(
parameters.Paths.Files.ArtifactsSourcePaths,
parameters.Paths.Directories.ArtifactsBin
);
});
Task("Zip-Files")
.IsDependentOn("Copy-Files")
.Does(() =>
{
var files = GetFiles( parameters.Paths.Directories.ArtifactsBin.FullPath + "/*")
- GetFiles(parameters.Paths.Directories.ArtifactsBin.FullPath + "/*.Testing.*");
Zip(parameters.Paths.Directories.ArtifactsBin, parameters.Paths.Files.ZipArtifactPath, files);
});
Task("Create-Chocolatey-Packages")
.IsDependentOn("Copy-Files")
.IsDependentOn("Package")
.WithCriteria(() => parameters.IsRunningOnWindows)
.Does(() =>
{
foreach(var package in parameters.Packages.Chocolatey)
{
// Create package.
ChocolateyPack(package.NuspecPath, new ChocolateyPackSettings {
Version = parameters.Version.SemVersion,
ReleaseNotes = parameters.ReleaseNotes.Notes.ToArray(),
OutputDirectory = parameters.Paths.Directories.NugetRoot,
Files = parameters.Paths.ChocolateyFiles
});
}
});
Task("Create-NuGet-Packages")
.IsDependentOn("Copy-Files")
.Does(() =>
{
foreach(var package in parameters.Packages.Nuget)
{
// Create package.
NuGetPack(package.NuspecPath, new NuGetPackSettings {
Version = parameters.Version.SemVersion,
ReleaseNotes = parameters.ReleaseNotes.Notes.ToArray(),
BasePath = parameters.Paths.Directories.ArtifactsBin,
OutputDirectory = parameters.Paths.Directories.NugetRoot,
Symbols = false,
NoPackageAnalysis = true
});
}
});
Task("Upload-AppVeyor-Artifacts")
.IsDependentOn("Create-Chocolatey-Packages")
.WithCriteria(() => parameters.IsRunningOnAppVeyor)
.Does(() =>
{
AppVeyor.UploadArtifact(parameters.Paths.Files.ZipArtifactPath);
foreach(var package in GetFiles(parameters.Paths.Directories.NugetRoot + "/*"))
{
AppVeyor.UploadArtifact(package);
}
});
Task("Publish-MyGet")
.IsDependentOn("Package")
.WithCriteria(() => !parameters.IsLocalBuild)
.WithCriteria(() => !parameters.IsPullRequest)
.WithCriteria(() => parameters.IsMainCakeRepo)
.WithCriteria(() => parameters.IsTagged || !parameters.IsMainCakeBranch)
.Does(() =>
{
// Resolve the API key.
var apiKey = EnvironmentVariable("MYGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet API key.");
}
// Resolve the API url.
var apiUrl = EnvironmentVariable("MYGET_API_URL");
if(string.IsNullOrEmpty(apiUrl)) {
throw new InvalidOperationException("Could not resolve MyGet API url.");
}
foreach(var package in parameters.Packages.All)
{
// Push the package.
NuGetPush(package.PackagePath, new NuGetPushSettings {
Source = apiUrl,
ApiKey = apiKey
});
}
})
.OnError(exception =>
{
Information("Publish-MyGet Task failed, but continuing with next Task...");
publishingError = true;
});
Task("Publish-NuGet")
.IsDependentOn("Create-NuGet-Packages")
.WithCriteria(() => !parameters.IsLocalBuild)
.WithCriteria(() => !parameters.IsPullRequest)
.WithCriteria(() => parameters.IsMainCakeRepo)
.WithCriteria(() => parameters.IsMainCakeBranch)
.WithCriteria(() => parameters.IsTagged)
.Does(() =>
{
// Resolve the API key.
var apiKey = EnvironmentVariable("NUGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve NuGet API key.");
}
// Resolve the API url.
var apiUrl = EnvironmentVariable("NUGET_API_URL");
if(string.IsNullOrEmpty(apiUrl)) {
throw new InvalidOperationException("Could not resolve NuGet API url.");
}
foreach(var package in parameters.Packages.Nuget)
{
// Push the package.
NuGetPush(package.PackagePath, new NuGetPushSettings {
ApiKey = apiKey,
Source = apiUrl
});
}
})
.OnError(exception =>
{
Information("Publish-NuGet Task failed, but continuing with next Task...");
publishingError = true;
});
Task("Publish-Chocolatey")
.IsDependentOn("Create-Chocolatey-Packages")
.WithCriteria(() => !parameters.IsLocalBuild)
.WithCriteria(() => !parameters.IsPullRequest)
.WithCriteria(() => parameters.IsMainCakeRepo)
.WithCriteria(() => parameters.IsMainCakeBranch)
.WithCriteria(() => parameters.IsTagged)
.Does(() =>
{
// Resolve the API key.
var apiKey = EnvironmentVariable("CHOCOLATEY_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve Chocolatey API key.");
}
// Resolve the API url.
var apiUrl = EnvironmentVariable("CHOCOLATEY_API_URL");
if(string.IsNullOrEmpty(apiUrl)) {
throw new InvalidOperationException("Could not resolve Chocolatey API url.");
}
foreach(var package in parameters.Packages.Chocolatey)
{
// Push the package.
ChocolateyPush(package.PackagePath, new ChocolateyPushSettings {
ApiKey = apiKey,
Source = apiUrl
});
}
})
.OnError(exception =>
{
Information("Publish-Chocolatey Task failed, but continuing with next Task...");
publishingError = true;
});
Task("Publish-HomeBrew")
.WithCriteria(() => !parameters.IsLocalBuild)
.WithCriteria(() => !parameters.IsPullRequest)
.WithCriteria(() => parameters.IsMainCakeRepo)
.WithCriteria(() => parameters.IsMainCakeBranch)
.WithCriteria(() => parameters.IsTagged)
.IsDependentOn("Zip-Files")
.Does(() =>
{
var hash = CalculateFileHash(parameters.Paths.Files.ZipArtifactPath).ToHex();
Information("Hash for creating HomeBrew PullRequest: {0}", hash);
})
.OnError(exception =>
{
Information("Publish-HomeBrew Task failed, but continuing with next Task...");
publishingError = true;
});
Task("Publish-GitHub-Release")
.WithCriteria(() => !parameters.IsLocalBuild)
.WithCriteria(() => !parameters.IsPullRequest)
.WithCriteria(() => parameters.IsMainCakeRepo)
.WithCriteria(() => parameters.IsMainCakeBranch)
.WithCriteria(() => parameters.IsTagged)
.Does(() =>
{
GitReleaseManagerAddAssets(parameters.GitHub.UserName, parameters.GitHub.Password, "cake-build", "cake", parameters.Version.Milestone, parameters.Paths.Files.ZipArtifactPath.ToString());
GitReleaseManagerClose(parameters.GitHub.UserName, parameters.GitHub.Password, "cake-build", "cake", parameters.Version.Milestone);
})
.OnError(exception =>
{
Information("Publish-GitHub-Release Task failed, but continuing with next Task...");
publishingError = true;
});
Task("Create-Release-Notes")
.Does(() =>
{
GitReleaseManagerCreate(parameters.GitHub.UserName, parameters.GitHub.Password, "cake-build", "cake", new GitReleaseManagerCreateSettings {
Milestone = parameters.Version.Milestone,
Name = parameters.Version.Milestone,
Prerelease = true,
TargetCommitish = "main"
});
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Package")
.IsDependentOn("Zip-Files")
.IsDependentOn("Create-NuGet-Packages");
Task("Default")
.IsDependentOn("Package");
Task("AppVeyor")
.IsDependentOn("Upload-AppVeyor-Artifacts")
.IsDependentOn("Publish-MyGet")
.IsDependentOn("Publish-NuGet")
.IsDependentOn("Publish-Chocolatey")
.IsDependentOn("Publish-HomeBrew")
.IsDependentOn("Publish-GitHub-Release")
.Finally(() =>
{
if(publishingError)
{
throw new Exception("An error occurred during the publishing of Cake. All publishing tasks have been attempted.");
}
});
Task("Travis")
.IsDependentOn("Run-Unit-Tests");
Task("ReleaseNotes")
.IsDependentOn("Create-Release-Notes");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(parameters.Target);