Skip to content

Commit fdb1df3

Browse files
committed
Add Sign-Bundle and Compress-Bundle Cake tasks
1 parent 739246f commit fdb1df3

File tree

1 file changed

+93
-4
lines changed

1 file changed

+93
-4
lines changed

build-macos.cake

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var netCoreProject = new {
7070
});
7171

7272

73-
Task("Package-Mac")
73+
Task("Create-Bundle")
7474
.IsDependentOn("Publish-NetCore")
7575
.Does(() =>
7676
{
@@ -83,7 +83,7 @@ var netCoreProject = new {
8383
Information("Copying Info.plist");
8484
EnsureDirectoryExists(tempDir.Combine("Contents"));
8585
CopyFileToDirectory($"{netCoreAppsRoot}/{netCoreApp}/Info.plist", tempDir.Combine("Contents"));
86-
86+
8787
// Update versions in Info.plist
8888
var plistFile = tempDir.Combine("Contents").CombineWithFilePath("Info.plist");
8989
dynamic plist = DeserializePlist(plistFile);
@@ -102,11 +102,100 @@ var netCoreProject = new {
102102
EnsureDirectoryExists(workingDir);
103103
MoveDirectory(tempDir, workingDir.Combine($"{macAppName}.app"));
104104

105-
var architecture = runtime[(runtime.IndexOf("-")+1)..];
106-
Zip(workingDir.FullPath, workingDir.CombineWithFilePath($"../{macAppName}-{architecture}.zip"));
105+
//var architecture = runtime[(runtime.IndexOf("-")+1)..];
106+
//Zip(workingDir.FullPath, workingDir.CombineWithFilePath($"../{macAppName}-{architecture}.zip"));
107107
}
108108
});
109109

110+
Task("Sign-Bundle")
111+
.IsDependentOn("Create-Bundle")
112+
.Does(() =>
113+
{
114+
var runtimeIdentifiers = netCoreProject.Runtimes.Where(r => r.StartsWith("osx"));
115+
var entitlementsFilePath = $"{netCoreAppsRoot}/{netCoreApp}/Entitlements.plist";
116+
117+
foreach(var runtime in runtimeIdentifiers)
118+
{
119+
Information($"Starting {runtime} macOS app signing");
120+
121+
var appBundlePath = artifactsDir.Combine(runtime).Combine($"{macAppName}.app");
122+
var signingIdentity = "Developer ID Application";
123+
124+
foreach (var dylib in GetFiles($"{appBundlePath}/**/*.dylib"))
125+
{
126+
Information($"Signing {dylib} library");
127+
128+
// Sign the library:
129+
var args = new ProcessArgumentBuilder();
130+
args.Append("--force");
131+
args.Append("--sign");
132+
args.AppendQuoted(signingIdentity);
133+
args.AppendQuoted(dylib.ToString());
134+
135+
StartProcess("codesign", new ProcessSettings
136+
{
137+
Arguments = args.RenderSafe(),
138+
RedirectStandardOutput = true,
139+
RedirectStandardError = true
140+
});
141+
}
142+
143+
// Sign the bundle:
144+
{
145+
Information($"Signing {appBundlePath} bundle");
146+
147+
var args = new ProcessArgumentBuilder();
148+
args.Append("--force");
149+
args.Append("--timestamp");
150+
args.Append("--options=runtime");
151+
args.Append("--entitlements " + entitlementsFilePath);
152+
args.Append("--sign");
153+
args.AppendQuoted(signingIdentity);
154+
args.AppendQuoted(appBundlePath.ToString());
155+
156+
StartProcess("codesign", new ProcessSettings
157+
{
158+
Arguments = args.RenderSafe(),
159+
RedirectStandardOutput = true,
160+
RedirectStandardError = true
161+
});
162+
}
163+
}
164+
});
165+
166+
Task("Compress-Bundle")
167+
.IsDependentOn("Sign-Bundle")
168+
.Does(() =>
169+
{
170+
var runtimeIdentifiers = netCoreProject.Runtimes.Where(r => r.StartsWith("osx"));
171+
foreach(var runtime in runtimeIdentifiers)
172+
{
173+
Information($"Compressing {runtime} macOS bundle");
174+
var appBundlePath = artifactsDir.Combine(runtime).Combine($"{macAppName}.app");
175+
var zippedPath = artifactsDir.Combine(runtime).CombineWithFilePath($"../{macAppName}.zip");
176+
177+
var args = new ProcessArgumentBuilder();
178+
args.Append("-c");
179+
args.Append("-k");
180+
args.Append("--keepParent");
181+
args.AppendQuoted(appBundlePath.ToString());
182+
args.AppendQuoted(zippedPath.ToString());
183+
184+
// "Ditto" is absolutely necessary instead of "zip" command.
185+
StartProcess("ditto", new ProcessSettings
186+
{
187+
Arguments = args.RenderSafe(),
188+
RedirectStandardOutput = true,
189+
RedirectStandardError = true
190+
});
191+
}
192+
});
193+
194+
Task("Package-Mac")
195+
.IsDependentOn("Create-Bundle")
196+
.IsDependentOn("Sign-Bundle")
197+
.IsDependentOn("Compress-Bundle");
198+
110199
Task("Default")
111200
.IsDependentOn("Restore-NetCore")
112201
.IsDependentOn("Publish-NetCore")

0 commit comments

Comments
 (0)