forked from MvvmCross/MvvmCross
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.cake
326 lines (292 loc) · 8.88 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
#tool nuget:?package=GitVersion.CommandLine
#tool nuget:?package=gitlink
#tool nuget:?package=vswhere
#addin "Cake.Incubator"
var sln = new FilePath("MvvmCross_All.sln");
var outputDir = new DirectoryPath("artifacts");
var nuspecDir = new DirectoryPath("nuspec");
var target = Argument("target", "Default");
var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
Task("Clean").Does(() =>
{
CleanDirectories("./**/bin");
CleanDirectories("./**/obj");
CleanDirectories(outputDir.FullPath);
});
GitVersion versionInfo = null;
Task("Version").Does(() => {
versionInfo = GitVersion(new GitVersionSettings {
UpdateAssemblyInfo = true,
OutputType = GitVersionOutput.Json
});
Information("GitVersion -> {0}", versionInfo.Dump());
});
Task("UpdateAppVeyorBuildNumber")
.IsDependentOn("Version")
.WithCriteria(() => isRunningOnAppVeyor)
.Does(() =>
{
AppVeyor.UpdateBuildVersion(versionInfo.FullBuildMetaData);
});
FilePath msBuildPath;
Task("ResolveBuildTools")
.Does(() =>
{
var vsLatest = VSWhereLatest();
msBuildPath = (vsLatest == null)
? null
: vsLatest.CombineWithFilePath("./MSBuild/15.0/Bin/MSBuild.exe");
});
Task("Restore")
.IsDependentOn("ResolveBuildTools")
.Does(() => {
NuGetRestore(sln, new NuGetRestoreSettings {
ToolPath = "tools/nuget.exe"
});
// MSBuild(sln, settings => settings.WithTarget("Restore"));
});
Task("Build")
.IsDependentOn("ResolveBuildTools")
.IsDependentOn("Clean")
.IsDependentOn("UpdateAppVeyorBuildNumber")
.IsDependentOn("Restore")
.Does(() => {
var settings = new MSBuildSettings
{
Configuration = "Release",
ToolPath = msBuildPath
};
settings.Properties.Add("DebugSymbols", new List<string> { "True" });
settings.Properties.Add("DebugType", new List<string> { "Full" });
MSBuild(sln, settings);
});
Task("GitLink")
.IsDependentOn("Build")
//pdbstr.exe and costura are not xplat currently
.WithCriteria(() => IsRunningOnWindows())
.WithCriteria(() =>
StringComparer.OrdinalIgnoreCase.Equals(versionInfo.BranchName, "develop") ||
IsMasterOrReleases())
.Does(() =>
{
var projectsToIgnore = new string[] {
"MasterDetailExample.Core",
"MasterDetailExample.Droid",
"MasterDetailExample.iOS",
"MasterDetailExample.UWP",
"PageRendererExample.Core",
"PageRendererExample.Droid",
"PageRendererExample.iOS",
"PageRendererExample.WindowsUWP",
"MvvmCross.iOS.Support.ExpandableTableView.Core",
"MvvmCross.iOS.Support.ExpandableTableView.iOS",
"MvvmCross.iOS.Support.JASidePanelsSample.Core",
"MvvmCross.iOS.Support.JASidePanelsSample.iOS",
"MvvmCross.iOS.Support.Tabs.Core",
"MvvmCross.iOS.Support.Tabs.iOS",
"MvvmCross.iOS.Support.XamarinSidebarSample.Core",
"MvvmCross.iOS.Support.XamarinSidebarSample.iOS",
"mvvmcross.codeanalysis.vsix",
"example",
"example.android",
"example.ios",
"example.windowsphone",
"example.core",
"example.droid",
"Example.W81",
"Eventhooks.Core",
"Eventhooks.Droid",
"Eventhooks.iOS",
"Eventhooks.Uwp",
"Eventhooks.Wpf",
"RoutingExample.Core",
"RoutingExample.iOS",
"RoutingExample.Droid",
"MvvmCross.TestProjects.CustomBinding.Core",
"MvvmCross.TestProjects.CustomBinding.iOS",
"MvvmCross.TestProjects.CustomBinding.Droid",
"playground",
"playground.core",
"playground.ios",
"MvxBindingsExample",
"MvxBindingsExample.Android",
"MvxBindingsExample.iOS",
"MvxBindingsExample.UWP"
};
GitLink("./",
new GitLinkSettings {
RepositoryUrl = "https://github.com/mvvmcross/mvvmcross",
Configuration = "Release",
SolutionFileName = "MvvmCross_All.sln",
ArgumentCustomization = args => args.Append("-ignore " + string.Join(",", projectsToIgnore))
});
});
Task("Package")
.IsDependentOn("GitLink")
.WithCriteria(() =>
StringComparer.OrdinalIgnoreCase.Equals(versionInfo.BranchName, "develop") ||
IsMasterOrReleases())
.Does(() =>
{
var nugetSettings = new NuGetPackSettings {
Authors = new [] { "MvvmCross contributors" },
Owners = new [] { "MvvmCross" },
IconUrl = new Uri("http://i.imgur.com/Baucn8c.png"),
ProjectUrl = new Uri("https://github.com/MvvmCross/MvvmCross"),
LicenseUrl = new Uri("https://raw.githubusercontent.com/MvvmCross/MvvmCross/develop/LICENSE"),
Copyright = "Copyright (c) MvvmCross",
RequireLicenseAcceptance = false,
Version = versionInfo.NuGetVersion,
Symbols = false,
NoPackageAnalysis = true,
OutputDirectory = outputDir,
Verbosity = NuGetVerbosity.Detailed,
BasePath = "./nuspec"
};
var nuspecs = new List<string> {
"MvvmCross.nuspec",
"MvvmCross.Binding.nuspec",
"MvvmCross.CodeAnalysis.nuspec",
"MvvmCross.Console.Platform.nuspec",
"MvvmCross.Core.nuspec",
"MvvmCross.Droid.FullFragging.nuspec",
"MvvmCross.Droid.Shared.nuspec",
"MvvmCross.Droid.Support.Core.UI.nuspec",
"MvvmCross.Droid.Support.Core.Utils.nuspec",
"MvvmCross.Droid.Support.Design.nuspec",
"MvvmCross.Droid.Support.Fragment.nuspec",
"MvvmCross.Droid.Support.V7.AppCompat.nuspec",
"MvvmCross.Droid.Support.V7.Preference.nuspec",
"MvvmCross.Droid.Support.V7.RecyclerView.nuspec",
"MvvmCross.Droid.Support.V14.Preference.nuspec",
"MvvmCross.Droid.Support.V17.Leanback.nuspec",
"MvvmCross.Forms.nuspec",
"MvvmCross.iOS.Support.nuspec",
"MvvmCross.iOS.Support.XamarinSidebar.nuspec",
"MvvmCross.Platform.nuspec",
"MvvmCross.Plugin.Accelerometer.nuspec",
"MvvmCross.Plugin.All.nuspec",
"MvvmCross.Plugin.Color.nuspec",
"MvvmCross.Plugin.DownloadCache.nuspec",
"MvvmCross.Plugin.Email.nuspec",
"MvvmCross.Plugin.FieldBinding.nuspec",
"MvvmCross.Plugin.File.nuspec",
"MvvmCross.Plugin.Json.nuspec",
"MvvmCross.Plugin.JsonLocalization.nuspec",
"MvvmCross.Plugin.Location.nuspec",
"MvvmCross.Plugin.Location.Fused.nuspec",
"MvvmCross.Plugin.Messenger.nuspec",
"MvvmCross.Plugin.MethodBinding.nuspec",
"MvvmCross.Plugin.Network.nuspec",
"MvvmCross.Plugin.PhoneCall.nuspec",
"MvvmCross.Plugin.PictureChooser.nuspec",
"MvvmCross.Plugin.ResourceLoader.nuspec",
"MvvmCross.Plugin.ResxLocalization.nuspec",
"MvvmCross.Plugin.Share.nuspec",
"MvvmCross.Plugin.Visibility.nuspec",
"MvvmCross.Plugin.WebBrowser.nuspec",
"MvvmCross.StarterPack.nuspec",
"MvvmCross.Tests.nuspec"
};
foreach(var nuspec in nuspecs)
{
NuGetPack(nuspecDir + "/" + nuspec, nugetSettings);
}
});
Task("PublishPackages")
.IsDependentOn("Package")
.WithCriteria(() => !BuildSystem.IsLocalBuild)
.WithCriteria(() => IsRepository("mvvmcross/mvvmcross"))
.WithCriteria(() =>
StringComparer.OrdinalIgnoreCase.Equals(versionInfo.BranchName, "develop") ||
IsMasterOrReleases())
.Does (() =>
{
if (StringComparer.OrdinalIgnoreCase.Equals(versionInfo.BranchName, "master") && !IsTagged())
{
Information("Packages will not be published as this release has not been tagged.");
return;
}
// Resolve the API key.
var nugetKeySource = GetNugetKeyAndSource();
var apiKey = nugetKeySource.Item1;
var source = nugetKeySource.Item2;
var nugetFiles = GetFiles(outputDir + "/*.nupkg");
foreach(var nugetFile in nugetFiles)
{
NuGetPush(nugetFile, new NuGetPushSettings {
Source = source,
ApiKey = apiKey
});
}
});
Task("Default")
.IsDependentOn("PublishPackages")
.Does(() =>
{
});
RunTarget(target);
bool IsMasterOrReleases()
{
if (StringComparer.OrdinalIgnoreCase.Equals(versionInfo.BranchName, "master"))
return true;
if (versionInfo.BranchName.Contains("releases/"))
return true;
return false;
}
bool IsRepository(string repoName)
{
if (isRunningOnAppVeyor)
{
var buildEnvRepoName = AppVeyor.Environment.Repository.Name;
Information("Checking repo name: {0} against build repo name: {1}", repoName, buildEnvRepoName);
return StringComparer.OrdinalIgnoreCase.Equals(repoName, buildEnvRepoName);
}
else
{
return true;
}
}
bool IsTagged()
{
var toReturn = false;
int commitsSinceTag = -1;
if (int.TryParse(versionInfo.CommitsSinceVersionSource, out commitsSinceTag))
{
// if tag is current commit this will be 0
if (commitsSinceTag == 0)
toReturn = true;
}
Information("Commits since tag {0}, is tagged: {1}", commitsSinceTag, toReturn);
return toReturn;
}
Tuple<string, string> GetNugetKeyAndSource()
{
var apiKeyKey = string.Empty;
var sourceKey = string.Empty;
if (isRunningOnAppVeyor)
{
apiKeyKey = "NUGET_APIKEY";
sourceKey = "NUGET_SOURCE";
}
else
{
if (StringComparer.OrdinalIgnoreCase.Equals(versionInfo.BranchName, "develop"))
{
apiKeyKey = "NUGET_APIKEY_DEVELOP";
sourceKey = "NUGET_SOURCE_DEVELOP";
}
else if (IsMasterOrReleases())
{
apiKeyKey = "NUGET_APIKEY_MASTER";
sourceKey = "NUGET_SOURCE_MASTER";
}
}
var apiKey = EnvironmentVariable(apiKeyKey);
if (string.IsNullOrEmpty(apiKey))
throw new Exception(string.Format("The {0} environment variable is not defined.", apiKeyKey));
var source = EnvironmentVariable(sourceKey);
if (string.IsNullOrEmpty(source))
throw new Exception(string.Format("The {0} environment variable is not defined.", sourceKey));
return Tuple.Create(apiKey, source);
}