From 0b588b8db4be085f595760bf504b30aaa944ddde Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 20 Sep 2024 18:45:40 +0800 Subject: [PATCH] Move packaging procedures into a single function in mac crafter Signed-off-by: Claudio Cambra --- .../mac-crafter/Sources/Utils/Packaging.swift | 49 +++++++++++++++++++ admin/osx/mac-crafter/Sources/main.swift | 43 ++++------------ 2 files changed, 59 insertions(+), 33 deletions(-) diff --git a/admin/osx/mac-crafter/Sources/Utils/Packaging.swift b/admin/osx/mac-crafter/Sources/Utils/Packaging.swift index 135b097b8..2e851a021 100644 --- a/admin/osx/mac-crafter/Sources/Utils/Packaging.swift +++ b/admin/osx/mac-crafter/Sources/Utils/Packaging.swift @@ -71,3 +71,52 @@ func signSparklePackage(sparkleTbzPath: String, buildPath: String, signKey: Stri throw PackagingError.packageSparkleSignError("Could not sign Sparkle package tbz!") } } + +func packageAppBundle( + productPath: String, + buildPath: String, + craftTarget: String, + craftBlueprintName: String, + appName: String, + packageSigningId: String?, + appleId: String?, + applePassword: String?, + appleTeamId: String?, + sparklePackageSignKey: String? +) throws { + print("Creating pkg file for client…") + let buildWorkPath = "\(buildPath)/\(craftTarget)/build/\(craftBlueprintName)/work/build" + let packagePath = try buildPackage( + appName: appName, + buildWorkPath: buildWorkPath, + productPath: productPath + ) + + if let packageSigningId { + print("Signing pkg with \(packageSigningId)…") + try signPackage(packagePath: packagePath, packageSigningId: packageSigningId) + + if let appleId, let applePassword, let appleTeamId { + print("Notarising pkg with Apple ID \(appleId)…") + try notarisePackage( + packagePath: packagePath, + appleId: appleId, + applePassword: applePassword, + appleTeamId: appleTeamId + ) + } + } + + print("Creating Sparkle TBZ file…") + let sparklePackagePath = + try buildSparklePackage(packagePath: packagePath, buildPath: buildPath) + + if let sparklePackageSignKey { + print("Signing Sparkle TBZ file…") + try signSparklePackage( + sparkleTbzPath: sparklePackagePath, + buildPath: buildPath, + signKey: sparklePackageSignKey + ) + } +} diff --git a/admin/osx/mac-crafter/Sources/main.swift b/admin/osx/mac-crafter/Sources/main.swift index fada690b4..87a23641e 100644 --- a/admin/osx/mac-crafter/Sources/main.swift +++ b/admin/osx/mac-crafter/Sources/main.swift @@ -228,41 +228,18 @@ struct Build: ParsableCommand { try fm.copyItem(atPath: clientAppDir, toPath: "\(productPath)/\(appName).app") if package { - print("Creating pkg file for client…") - let buildWorkPath = "\(clientBuildDir)/work/build" - let packagePath = try buildPackage( + try packageAppBundle( + productPath: productPath, + buildPath: buildPath, + craftTarget: craftTarget, + craftBlueprintName: craftBlueprintName, appName: appName, - buildWorkPath: buildWorkPath, - productPath: productPath + packageSigningId: packageSigningId, + appleId: appleId, + applePassword: applePassword, + appleTeamId: appleTeamId, + sparklePackageSignKey: sparklePackageSignKey ) - - if let packageSigningId { - print("Signing pkg with \(packageSigningId)…") - try signPackage(packagePath: packagePath, packageSigningId: packageSigningId) - - if let appleId, let applePassword, let appleTeamId { - print("Notarising pkg with Apple ID \(appleId)…") - try notarisePackage( - packagePath: packagePath, - appleId: appleId, - applePassword: applePassword, - appleTeamId: appleTeamId - ) - } - } - - print("Creating Sparkle TBZ file…") - let sparklePackagePath = - try buildSparklePackage(packagePath: packagePath, buildPath: buildPath) - - if let sparklePackageSignKey { - print("Signing Sparkle TBZ file…") - try signSparklePackage( - sparkleTbzPath: sparklePackagePath, - buildPath: buildPath, - signKey: sparklePackageSignKey - ) - } } print("Done!")