Add ability to notarise package from mac-crafter
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 19 Sep 2024 13:01:39 +0000 (21:01 +0800)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Tue, 24 Sep 2024 02:17:45 +0000 (10:17 +0800)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
admin/osx/mac-crafter/Sources/Utils/Packaging.swift
admin/osx/mac-crafter/Sources/main.swift

index 1da19d539480c1bf7faedde16e865b9facd7d88b..e22a341402d121833aa552a6e25483009d1848ce 100644 (file)
@@ -18,6 +18,7 @@ enum PackagingError: Error {
     case projectNameSettingError(String)
     case packageBuildError(String)
     case packageSigningError(String)
+    case packageNotarisationError(String)
 }
 
 func buildPackage(buildWorkPath: String, productPath: String) throws -> String {
@@ -45,3 +46,14 @@ func signPackage(packagePath: String, packageSigningId: String) throws {
     try fm.moveItem(atPath: packagePathNew, toPath: packagePath)
 }
 
+func notarisePackage(
+    packagePath: String, appleId: String, applePassword: String, appleTeamId: String
+) throws {
+    guard shell("xcrun notarytool submit \(packagePath) --apple-id \(appleId) --password \(applePassword) --team-id \(appleTeamId) --wait") == 0 else {
+        throw PackagingError.packageNotarisationError("Failure when notarising package!")
+    }
+    guard shell("xcrun stapler staple \(packagePath)") == 0 else {
+        throw PackagingError.packageNotarisationError("Could not staple notarisation on package!")
+    }
+}
+
index 4ba8d75dc7c88351a074579ecc933fa57697b379..c5cae7b3026a040e1951eebe6a385bda0b14de32 100644 (file)
@@ -65,6 +65,15 @@ struct Build: ParsableCommand {
     @Option(name: [.long], help: "Git clone command; include options such as depth.")
     var gitCloneCommand = "git clone --depth=1"
 
+    @Option(name: [.long], help: "Apple ID, used for notarisation.")
+    var appleId: String?
+
+    @Option(name: [.long], help: "Apple ID password, used for notarisation.")
+    var applePassword: String?
+
+    @Option(name: [.long], help: "Apple Team ID, used for notarisation.")
+    var appleTeamId: String?
+
     @Option(name: [.long], help: "Apple package signing ID.")
     var packageSigningId: String?
 
@@ -222,6 +231,15 @@ struct Build: ParsableCommand {
 
             if let packageSigningId {
                 try signPackage(packagePath: packagePath, packageSigningId: packageSigningId)
+
+                if let appleId, let applePassword, let appleTeamId {
+                    try notarisePackage(
+                        packagePath: packagePath,
+                        appleId: appleId,
+                        applePassword: applePassword,
+                        appleTeamId: appleTeamId
+                    )
+                }
             }
         }