forked from cake-contrib/Cake_Git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
316 lines (272 loc) · 11.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
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var isLocalBuild = !AppVeyor.IsRunningOnAppVeyor;
var isPullRequest = AppVeyor.Environment.PullRequest.IsPullRequest;
var solutions = GetFiles("./**/*.sln");
var solutionPaths = solutions.Select(solution => solution.GetDirectory());
var releaseNotes = ParseReleaseNotes("./ReleaseNotes.md");
var version = releaseNotes.Version.ToString();
var binDir = MakeAbsolute(Directory("./src/Cake.Git/bin/" + configuration + "/net461"));
var nugetRoot = "./nuget/";
var artifactsRoot = MakeAbsolute(Directory("./artifacts/"));
var semVersion = isLocalBuild
? version
: string.Concat(version, "-build-", AppVeyor.Environment.Build.Number.ToString("0000"));
var assemblyInfo = new AssemblyInfoSettings {
Title = "Cake.Git",
Description = "Cake Git AddIn",
Product = "Cake.Git",
Company = "WCOM AB",
Version = version,
FileVersion = version,
InformationalVersion = semVersion,
Copyright = string.Format("Copyright © WCOM AB {0}", DateTime.Now.Year),
CLSCompliant = true
};
var nuGetPackSettings = new NuGetPackSettings {
Id = assemblyInfo.Product,
Version = assemblyInfo.InformationalVersion,
Title = assemblyInfo.Title,
Authors = new[] {assemblyInfo.Company},
Owners = new[] {assemblyInfo.Company, "cake-contrib"},
Description = assemblyInfo.Description,
Summary = "Cake AddIn that extends Cake with Git SCM features",
ProjectUrl = new Uri("https://github.com/cake-contrib/Cake_Git/"),
IconUrl = new Uri("https://cdn.rawgit.com/cake-contrib/graphics/a5cf0f881c390650144b2243ae551d5b9f836196/png/cake-contrib-medium.png"),
LicenseUrl = new Uri("https://github.com/cake-contrib/Cake_Git/blob/master/LICENSE.md"),
Copyright = assemblyInfo.Copyright,
ReleaseNotes = releaseNotes.Notes.ToArray(),
Tags = new [] {"Cake", "Script", "Build", "Git"},
RequireLicenseAcceptance= false,
Symbols = false,
NoPackageAnalysis = true,
Files = new NuSpecContent[0], // is set dynamically
BasePath = artifactsRoot,
OutputDirectory = nugetRoot
};
var msBuildSettings = new DotNetCoreMSBuildSettings()
.WithProperty("Version", semVersion)
.WithProperty("AssemblyVersion", version)
.WithProperty("FileVersion", version)
.WithProperty("PackageReleaseNotes", string.Concat("\"", string.Concat(releaseNotes.Notes.ToArray()), "\""));
Context.Tools.RegisterFile("./tools/nuget.exe");
if (!isLocalBuild)
{
AppVeyor.UpdateBuildVersion(semVersion);
}
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
var buildStartMessage = string.Format(
"Building version {0} of {1} ({2}).",
version,
assemblyInfo.Product,
semVersion
);
Information(buildStartMessage);
if(!IsRunningOnWindows())
{
var frameworkPathOverride = new FilePath(typeof(object).Assembly.Location).GetDirectory().FullPath + "/";
// Use FrameworkPathOverride when not running on Windows.
Information("Build will use FrameworkPathOverride={0} since not building on Windows.", frameworkPathOverride);
msBuildSettings.WithProperty("FrameworkPathOverride", frameworkPathOverride);
}
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
// Clean solution directories.
foreach(var path in solutionPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/**/bin/" + configuration);
CleanDirectories(path + "/**/obj/" + configuration);
}
Information("Cleaning {0}", nugetRoot);
CleanDirectory(MakeAbsolute(Directory(nugetRoot)));
Information("Cleaning {0}", artifactsRoot);
CleanDirectory(artifactsRoot);
});
Task("Restore")
.Does(() =>
{
// Restore all NuGet packages.
foreach(var solution in solutions)
{
Information("Restoring {0}...", solution);
DotNetCoreRestore(
solution.FullPath,
new DotNetCoreRestoreSettings {
Verbosity = DotNetCoreVerbosity.Minimal,
MSBuildSettings = msBuildSettings
});
}
});
Task("SolutionInfo")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
var file = "./src/SolutionInfo.cs";
CreateAssemblyInfo(file, assemblyInfo);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("SolutionInfo")
.Does(() =>
{
// Build all solutions.
foreach(var solution in solutions)
{
Information("Building {0}", solution);
DotNetCoreBuild(
solution.FullPath,
new DotNetCoreBuildSettings {
Configuration = configuration,
NoRestore = true,
MSBuildSettings = msBuildSettings
});
}
});
Task("Publish-Artifacts")
.IsDependentOn("Build")
.Does(() =>
{
if (!DirectoryExists(artifactsRoot))
{
CreateDirectory(artifactsRoot);
}
DotNetCorePublish("./src/Cake.Git", new DotNetCorePublishSettings
{
NoRestore = true,
Framework = "net461",
MSBuildSettings = msBuildSettings,
OutputDirectory = artifactsRoot + "/net461"
});
DotNetCorePublish("./src/Cake.Git", new DotNetCorePublishSettings
{
NoRestore = true,
Framework = "netstandard2.0",
MSBuildSettings = msBuildSettings,
OutputDirectory = artifactsRoot + "/netstandard2.0"
});
});
Task("Create-NuGet-Package")
.IsDependentOn("Publish-Artifacts")
.Does(() =>
{
var native = GetFiles(artifactsRoot.FullPath + "/net461/lib/**/*");
var cakeGit = GetFiles(artifactsRoot.FullPath + "/**/Cake.Git.dll");
var libGit = GetFiles(artifactsRoot.FullPath + "/**/LibGit2Sharp*");
var coreNative = GetFiles(artifactsRoot.FullPath + "/netstandard2.0/runtimes/**/*")
- GetFiles(artifactsRoot.FullPath + "/netstandard2.0/runtimes/win7-x86/**/*");
nuGetPackSettings.Files = (native + libGit + cakeGit)
.Where(file=>!file.FullPath.Contains("Cake.Core.") && !file.FullPath.Contains("/runtimes/"))
.Select(file=>file.FullPath.Substring(artifactsRoot.FullPath.Length+1))
.Select(file=>new NuSpecContent {Source = file, Target = "lib/" + file})
.Union(
coreNative
.Select(file=>new NuSpecContent {
Source = file.FullPath.Substring(artifactsRoot.FullPath.Length+1),
Target = "lib/netstandard2.0/" + file.GetFilename()
})
)
.ToArray();
if (!DirectoryExists(nugetRoot))
{
CreateDirectory(nugetRoot);
}
NuGetPack(nuGetPackSettings);
});
Task("Test")
.IsDependentOn("Create-NuGet-Package")
.WithCriteria(() => StringComparer.OrdinalIgnoreCase.Equals(configuration, "Release"))
.Does(() =>
{
var package = nugetRoot + "Cake.Git." + semVersion + ".nupkg";
var addinDir = MakeAbsolute(Directory("./tools/Addins/Cake.Git/Cake.Git"));
if (DirectoryExists(addinDir))
{
DeleteDirectory(addinDir, new DeleteDirectorySettings {
Recursive = true,
Force = true
});
}
Unzip(package, addinDir);
Action executeTests = ()=> {
CakeExecuteScript("./testnet461.cake",
new CakeSettings{
Arguments = new Dictionary<string, string>{
{"target", target == "Default" ? "Default-Tests" : "Local-Tests"}}});
DotNetCoreExecute(
"./tools/Cake.CoreCLR/Cake.dll",
string.Concat("testnetstandard2.cake --target=", target == "Default" ? "Default-Tests" : "Local-Tests")
);
};
if (TravisCI.IsRunningOnTravisCI)
{
using(TravisCI.Fold("Execute-Tests"))
{
executeTests();
return;
}
}
executeTests();
});
Task("Publish-MyGet")
.IsDependentOn("Create-NuGet-Package")
.IsDependentOn("Test")
.WithCriteria(() => !isLocalBuild)
.WithCriteria(() => !isPullRequest)
.Does(() =>
{
// Resolve the API key.
var apiKey = EnvironmentVariable("MYGET_API_KEY");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet API key.");
}
var source = EnvironmentVariable("MYGET_SOURCE");
if(string.IsNullOrEmpty(apiKey)) {
throw new InvalidOperationException("Could not resolve MyGet source.");
}
// Get the path to the package.
var package = nugetRoot + "Cake.Git." + semVersion + ".nupkg";
// Push the package.
NuGetPush(package, new NuGetPushSettings {
Source = source,
ApiKey = apiKey
});
});
Task("Default")
.IsDependentOn("Create-NuGet-Package")
.IsDependentOn("Test");
Task("Local-Tests")
.IsDependentOn("Create-NuGet-Package")
.IsDependentOn("Test");
Task("AppVeyor")
.IsDependentOn("Publish-MyGet");
Task("Travis")
.IsDependentOn("Test");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);