-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
210 lines (184 loc) · 7.78 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
#addin "Cake.Plist"
#addin "Cake.AndroidAppManifest"
#addin "Cake.MobileCenter"
var configFile = "build.xml";
/// ARGUMENTS
var target = Argument("target", "Default");
var branch = EnvironmentVariable("MOBILECENTER_BRANCH") ?? Argument("branch", "master");
var buildId = EnvironmentVariable ("MOBILECENTER_BUILD_ID") ?? Argument("buildId", "0");
var output = EnvironmentVariable("MOBILECENTER_OUTPUT_DIRECTORY") ?? Argument("output", "temp");
var args = new
{
Sources = EnvironmentVariable("MOBILECENTER_SOURCE_DIRECTORY") ?? Argument("sources", "."),
Output = output,
Branch = branch,
Android = new
{
Name = XmlPeek(configFile, $"/config/android/{branch}/@displayName") ?? Argument<string>("android_displayName"),
BundleId = XmlPeek(configFile, $"/config/android/{branch}/@bundleId") ?? Argument<string>("android_bundleId"),
Version = XmlPeek(configFile, $"/config/android/{branch}/@version") ?? Argument<string>("android_version"),
BuildNumber = buildId,
UITestOutput = "",
MobileCenter = new
{
Token = Argument("android_mc_token", "none"),
AppId = XmlPeek(configFile, $"/config/android/mobile-center/@appid") ?? Argument("android_mc_appid", "none"),
Locale = XmlPeek(configFile, $"/config/android/mobile-center/@locale") ?? Argument("android_mc_locale", "en_US"),
DeviceSet = XmlPeek(configFile, $"/config/android/mobile-center/@deviceSet") ?? Argument("android_mc_deviceset", "none"),
},
},
iOS = new
{
Name = XmlPeek(configFile, $"/config/ios/{branch}/@displayName") ?? Argument<string>("ios_displayName"),
BundleId = XmlPeek(configFile, $"/config/ios/{branch}/@bundleId") ?? Argument<string>("ios_bundleId"),
Version = XmlPeek(configFile, $"/config/ios/{branch}/@version") ?? Argument<string>("ios_version"),
BuildNumber = buildId,
MobileCenter = new
{
Token = Argument("ios_mc_token", "none"),
AppId = XmlPeek(configFile, $"/config/ios/mobile-center/@appid") ?? Argument("ios_mc_appid", "none"),
Locale = XmlPeek(configFile, $"/config/ios/mobile-center/@locale") ?? Argument("ios_mc_locale", "en_US"),
DeviceSet = XmlPeek(configFile, $"/config/ios/mobile-center/@deviceSet") ?? Argument("ios_mc_deviceset", "none"),
},
}
};
/// TOOLS
Task("Tools.PrintArguments").Does(() =>
{
Information($"Arguments:");
Information($" * Target: {target}");
Information($" * Sources: {args.Sources}");
Information($" * Branch: {args.Branch}");
Information($" * Android:");
Information($" - Name: {args.Android.Name}");
Information($" - BundleId: {args.Android.BundleId}");
Information($" - Version: {args.Android.Version}");
Information($" - BuildNumber: {args.Android.BuildNumber}");
Information($" - MobileCenter:");
Information($" - Token: <*>");
Information($" - AppId: {args.Android.MobileCenter.AppId}");
Information($" - Locale: {args.Android.MobileCenter.Locale}");
Information($" - DeviceSet: {args.Android.MobileCenter.DeviceSet}");
Information($" * iOS:");
Information($" - Name: {args.iOS.Name}");
Information($" - BundleId: {args.iOS.BundleId}");
Information($" - Version: {args.iOS.Version}");
Information($" - BuildNumber: {args.iOS.BuildNumber}");
Information($" - MobileCenter:");
Information($" - Token: <*>");
Information($" - AppId: {args.iOS.MobileCenter.AppId}");
Information($" - Locale: {args.iOS.MobileCenter.Locale}");
Information($" - DeviceSet: {args.iOS.MobileCenter.DeviceSet}");
});
Task("Tools.Help")
.IsDependentOn("Tools.PrintArguments")
.Does(() =>
{
Information($"Available targets:");
Information($" * 'iOS.Prepare': prepare iOS package");
Information($" * 'iOS.Build': build the iOS package");
Information($" * 'Android.Prepare': prepare Android package");
Information($" * 'Android.Build': build the Android package");
Information($" * 'MobileCenter.iOS.Test': executes iOS UI Tests from Mobile Center");
Information($" * 'MobileCenter.Android.Test': executes Android UI Tests from Mobile Center");
});
Task("Tools.Clean").Does(() =>
{
CleanDirectory($"temp");
});
/// PREPARE
Task("iOS.Prepare").Does(() =>
{
var manifestFiles = GetFiles(System.IO.Path.Combine(args.Sources, "**/Info.plist"));
foreach(var appmanifest in manifestFiles)
{
Information($"Updating manifest '{appmanifest}' ...");
dynamic data = DeserializePlist(appmanifest);
data["CFBundleShortVersionString"] = args.iOS.Version;
data["CFBundleVersion"] = args.iOS.BuildNumber;
data["CFBundleName"] = args.iOS.Name;
data["CFBundleIdentifier"] = args.iOS.BundleId;
SerializePlist(appmanifest, data);
}
});
Task("Android.Prepare").Does(() =>
{
var manifestFiles = GetFiles(System.IO.Path.Combine(args.Sources, "**/Properties/AndroidManifest.xml"));
foreach(var appmanifest in manifestFiles)
{
Information($"Updating manifest '{appmanifest}' ...");
var path = new FilePath(appmanifest.FullPath);
var manifest = DeserializeAppManifest(path);
manifest.PackageName = args.Android.BundleId;
manifest.VersionName = args.Android.Version;
manifest.VersionCode = int.Parse(args.Android.BuildNumber);
manifest.ApplicationLabel = args.Android.Name;
manifest.Debuggable = false;
SerializeAppManifest(path, manifest);
}
});
/// MOBILECENTER : TEST
Task("MobileCenter.Test.Build")
.Does(() =>
{
var dir = MakeAbsolute(Directory(args.Output) + Directory("UITest"));
var testCsproj = GetFiles(System.IO.Path.Combine(dir.FullPath, "**/*.UITests.csproj")).FirstOrDefault();
MSBuild(testCsproj, c =>
{
c.MSBuildPlatform = Cake.Common.Tools.MSBuild.MSBuildPlatform.x86;
c.SetConfiguration("Release").WithProperty("OutputPath", dir.FullPath);
});
});
Task("MobileCenter.Test.iOS")
.IsDependentOn("MobileCenter.Test.Build")
.Does(() =>
{
var dir = MakeAbsolute(Directory(args.Output) + Directory("UITest"));
var ipaFiles = GetFiles(System.IO.Path.Combine(args.Output, "**/*.ipa"));
foreach(var ipa in ipaFiles)
{
MobileCenterTestRunUitest(new MobileCenterTestRunUitestSettings
{
App = args.iOS.MobileCenter.AppId,
AppPath = ipa.FullPath,
BuildDir = dir.FullPath,
TestSeries = args.Branch,
Locale = args.iOS.MobileCenter.Locale,
Devices = args.iOS.MobileCenter.DeviceSet,
Token = args.iOS.MobileCenter.Token,
});
}
});
Task("MobileCenter.Test.Android")
.IsDependentOn("MobileCenter.Test.Build")
.Does(() =>
{
var dir = MakeAbsolute(Directory(args.Output) + Directory("UITest"));
var apkFiles = GetFiles(System.IO.Path.Combine(args.Output, "**/*.apk"));
foreach(var apk in apkFiles)
{
MobileCenterTestRunUitest(new MobileCenterTestRunUitestSettings
{
App = args.Android.MobileCenter.AppId,
AppPath = apk.FullPath,
BuildDir = dir.FullPath,
TestSeries = args.Branch,
Locale = args.Android.MobileCenter.Locale,
Devices = args.Android.MobileCenter.DeviceSet,
Token = args.Android.MobileCenter.Token,
});
}
});
/// MOBILECENTER : MAIN
Task("MobileCenter.Pre.iOS")
.IsDependentOn("iOS.Prepare");
Task("MobileCenter.Pre.Android")
.IsDependentOn("Android.Prepare");
Task("MobileCenter.Post.iOS")
.IsDependentOn("MobileCenter.Test.iOS");
Task("MobileCenter.Post.Android")
.IsDependentOn("MobileCenter.Test.Android");
/// RUN
Task("Default")
.IsDependentOn("Tools.Help");
RunTarget(target);