-
-
Notifications
You must be signed in to change notification settings - Fork 198
/
build-macos.cake
115 lines (92 loc) · 3.73 KB
/
build-macos.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
#addin "Cake.Plist"
var target = Argument("target", "Default");
var platform = Argument("platform", "AnyCPU");
var configuration = Argument("configuration", "Release");
var version = EnvironmentVariable("APPVEYOR_BUILD_VERSION") ?? Argument("version", "0.0.1");
var artifactsDir = (DirectoryPath)Directory("./artifacts");
var netCoreAppsRoot= "./src";
var netCoreApp = "StructuredLogViewer.Avalonia";
var macAppName = "StructuredLogViewer";
var buildDirs =
GetDirectories($"{netCoreAppsRoot}/**/bin/**") +
GetDirectories($"{netCoreAppsRoot}/**/obj/**") +
GetDirectories($"{netCoreAppsRoot}/artifacts/*");
var netCoreProject = new {
Path = $"{netCoreAppsRoot}/{netCoreApp}",
Name = netCoreApp,
Framework = XmlPeek($"{netCoreAppsRoot}/{netCoreApp}/{netCoreApp}.csproj", "//*[local-name()='TargetFramework']/text()"),
Runtimes = XmlPeek($"{netCoreAppsRoot}/{netCoreApp}/{netCoreApp}.csproj", "//*[local-name()='RuntimeIdentifiers']/text()").Split(';')
};
Task("Clean")
.Does(()=>{
CleanDirectories(buildDirs);
});
Task("Restore-NetCore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetRestore(netCoreProject.Path);
});
Task("Build-NetCore")
.IsDependentOn("Restore-NetCore")
.Does(() =>
{
Information("Building: {0}", netCoreProject.Name);
DotNetBuild(netCoreProject.Path, new DotNetBuildSettings {
Configuration = configuration
});
});
Task("Publish-NetCore")
.IsDependentOn("Restore-NetCore")
.Does(() =>
{
foreach(var runtime in netCoreProject.Runtimes)
{
if (!runtime.Contains("osx"))
continue;
var outputDir = artifactsDir.Combine(runtime);
Information("Publishing: {0}, runtime: {1}", netCoreProject.Name, runtime);
DotNetPublish(netCoreProject.Path, new DotNetPublishSettings {
//Framework = netCoreProject.Framework,
Configuration = configuration,
Runtime = runtime,
SelfContained = true,
OutputDirectory = outputDir.FullPath
});
}
});
Task("Package-Mac")
.IsDependentOn("Publish-NetCore")
.Does(() =>
{
var runtimeIdentifiers = netCoreProject.Runtimes.Where(r => r.StartsWith("osx"));
foreach(var runtime in runtimeIdentifiers)
{
var workingDir = artifactsDir.Combine(runtime);
var tempDir = artifactsDir.Combine("app");
Information("Copying Info.plist");
EnsureDirectoryExists(tempDir.Combine("Contents"));
CopyFileToDirectory($"{netCoreAppsRoot}/{netCoreApp}/Info.plist", tempDir.Combine("Contents"));
// Update versions in Info.plist
var plistFile = tempDir.Combine("Contents").CombineWithFilePath("Info.plist");
dynamic plist = DeserializePlist(plistFile);
plist["CFBundleShortVersionString"] = version;
plist["CFBundleVersion"] = version;
SerializePlist(plistFile, plist);
Information("Copying App Icons");
EnsureDirectoryExists(tempDir.Combine("Contents/Resources"));
CopyFileToDirectory($"{netCoreAppsRoot}/{netCoreApp}/StructuredLogViewer.icns", tempDir.Combine("Contents/Resources"));
Information("Copying executables");
MoveDirectory(workingDir, tempDir.Combine("Contents/MacOS"));
Information("Finish packaging");
EnsureDirectoryExists(workingDir);
MoveDirectory(tempDir, workingDir.Combine($"{macAppName}.app"));
var architecture = runtime[(runtime.IndexOf("-")+1)..];
Zip(workingDir.FullPath, workingDir.CombineWithFilePath($"../{macAppName}-{architecture}.zip"));
}
});
Task("Default")
.IsDependentOn("Restore-NetCore")
.IsDependentOn("Publish-NetCore")
.IsDependentOn("Package-Mac");
RunTarget(target);