From 5c37056004e869746b52b5d187289756c6afa7bc Mon Sep 17 00:00:00 2001 From: Edgars Simanovskis Date: Tue, 14 Mar 2023 11:11:39 +0700 Subject: [PATCH 1/6] [310] Support multiple apple accounts --- fastlane/Constants/Constant.swift | 20 +++++++++++++++++-- fastlane/Fastfile.swift | 6 +++--- fastlane/Helpers/AppStoreAuthentication.swift | 2 +- fastlane/Helpers/Match.swift | 10 +++++----- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/fastlane/Constants/Constant.swift b/fastlane/Constants/Constant.swift index e8dfa15c..cd94ebfa 100644 --- a/fastlane/Constants/Constant.swift +++ b/fastlane/Constants/Constant.swift @@ -22,8 +22,10 @@ enum Constant { // MARK: - Match - static let userName = "<#userName#>" - static let teamId = "<#teamId#>" + static let appleStagingUserName = "<#userName#>" + static let appleStagingTeamId = "<#teamId#>" + static let appleProductionUserName = "<#userName#>" + static let appleProductionTeamId = "<#teamId#>" static let keychainName = "github_action_keychain" static let matchURL = "git@github.com:{organization}/{repo}.git" @@ -117,6 +119,20 @@ extension Constant { let outputDirectoryURL = URL(fileURLWithPath: Constant.outputPath) return outputDirectoryURL.appendingPathComponent(productName + ".app" + Constant.dSYMSuffix).relativePath } + + var appleUsername: String { + switch self { + case .staging: return Constant.appleStagingUserName + case .production: return Constant.appleProductionUserName + } + } + + var appleTeamId: String { + switch self { + case .staging: return Constant.appleStagingTeamId + case .production: return Constant.appleProductionTeamId + } + } } enum BuildType: String { diff --git a/fastlane/Fastfile.swift b/fastlane/Fastfile.swift index b1dc07bd..46f1ae3a 100644 --- a/fastlane/Fastfile.swift +++ b/fastlane/Fastfile.swift @@ -107,7 +107,7 @@ class Fastfile: LaneFile { desc("Build Production app and upload to App Store") setAppVersion() - AppStoreAuthentication.connectAPIKey() + AppStoreAuthentication.connectProductionAPIKey() if Secret.bumpAppStoreBuildNumber { bumpAppstoreBuild() } else { @@ -131,7 +131,7 @@ class Fastfile: LaneFile { buildAppStoreLane() - AppStoreAuthentication.connectAPIKey() + AppStoreAuthentication.connectProductionAPIKey() Distribution.uploadToTestFlight() Symbol.uploadToCrashlytics(environment: .production) @@ -167,7 +167,7 @@ class Fastfile: LaneFile { registerDevice( name: deviceName, udid: deviceUDID, - teamId: .userDefined(Constant.teamId) + teamId: .userDefined(Constant.appleStagingTeamId) ) Match.syncCodeSigning(type: .development, environment: .staging, isForce: true) diff --git a/fastlane/Helpers/AppStoreAuthentication.swift b/fastlane/Helpers/AppStoreAuthentication.swift index 8eaded06..7435d50b 100644 --- a/fastlane/Helpers/AppStoreAuthentication.swift +++ b/fastlane/Helpers/AppStoreAuthentication.swift @@ -10,7 +10,7 @@ import Foundation enum AppStoreAuthentication { - static func connectAPIKey() { + static func connectProductionAPIKey() { appStoreConnectApiKey( keyId: Secret.appStoreKeyIdKey, issuerId: Secret.appStoreIssuerIdKey, diff --git a/fastlane/Helpers/Match.swift b/fastlane/Helpers/Match.swift index 7065e442..2bcdd392 100644 --- a/fastlane/Helpers/Match.swift +++ b/fastlane/Helpers/Match.swift @@ -15,8 +15,8 @@ enum Match { type: type.match, readonly: .userDefined(!isForce), appIdentifier: [environment.bundleId], - username: .userDefined(Constant.userName), - teamId: .userDefined(Constant.teamId), + username: .userDefined(environment.appleUsername), + teamId: .userDefined(environment.appleTeamId), gitUrl: Constant.matchURL, keychainName: Constant.keychainName, keychainPassword: .userDefined(Secret.keychainPassword), @@ -27,8 +27,8 @@ enum Match { type: type.match, readonly: .userDefined(!isForce), appIdentifier: [environment.bundleId], - username: .userDefined(Constant.userName), - teamId: .userDefined(Constant.teamId), + username: .userDefined(environment.appleUsername), + teamId: .userDefined(environment.appleTeamId), gitUrl: Constant.matchURL, force: .userDefined(isForce) ) @@ -41,7 +41,7 @@ enum Match { updateCodeSigningSettings( path: Constant.projectPath, useAutomaticSigning: .userDefined(false), - teamId: .userDefined(Constant.teamId), + teamId: .userDefined(environment.appleTeamId), targets: .userDefined([Constant.projectName]), buildConfigurations: .userDefined([Self.createBuildConfiguration(type: type, environment: environment)]), codeSignIdentity: .userDefined(type.codeSignIdentity), From f7f7530e58255ec18277423d1eb66d623325edf4 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 19 Apr 2023 11:50:12 +0700 Subject: [PATCH 2/6] [310] Fix Production Scheme --- fastlane/Constants/Constant.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fastlane/Constants/Constant.swift b/fastlane/Constants/Constant.swift index cd94ebfa..c77b3cee 100644 --- a/fastlane/Constants/Constant.swift +++ b/fastlane/Constants/Constant.swift @@ -84,14 +84,14 @@ extension Constant { case production = "Production" var productName: String { "\(Constant.projectName) \(rawValue)".trimmed } - + var scheme: String { switch self { case .staging: return "\(Constant.projectName) \(rawValue)".trimmed - case .production: return Constant.projectName + case .production: return Constant.projectName.trimmed } } - + var bundleId: String { switch self { case .staging: return Constant.stagingBundleId From 54bd28f9aaa11a1a295c1b78c066d84d680ebe60 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 21 Apr 2023 14:44:53 +0700 Subject: [PATCH 3/6] [310] Rename connectProductionAPIKey -> connectAPIKey --- fastlane/Fastfile.swift | 4 ++-- fastlane/Helpers/AppStoreAuthentication.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fastlane/Fastfile.swift b/fastlane/Fastfile.swift index 46f1ae3a..ccba6fe1 100644 --- a/fastlane/Fastfile.swift +++ b/fastlane/Fastfile.swift @@ -107,7 +107,7 @@ class Fastfile: LaneFile { desc("Build Production app and upload to App Store") setAppVersion() - AppStoreAuthentication.connectProductionAPIKey() + AppStoreAuthentication.connectAPIKey() if Secret.bumpAppStoreBuildNumber { bumpAppstoreBuild() } else { @@ -131,7 +131,7 @@ class Fastfile: LaneFile { buildAppStoreLane() - AppStoreAuthentication.connectProductionAPIKey() + AppStoreAuthentication.connectAPIKey() Distribution.uploadToTestFlight() Symbol.uploadToCrashlytics(environment: .production) diff --git a/fastlane/Helpers/AppStoreAuthentication.swift b/fastlane/Helpers/AppStoreAuthentication.swift index 7435d50b..8eaded06 100644 --- a/fastlane/Helpers/AppStoreAuthentication.swift +++ b/fastlane/Helpers/AppStoreAuthentication.swift @@ -10,7 +10,7 @@ import Foundation enum AppStoreAuthentication { - static func connectProductionAPIKey() { + static func connectAPIKey() { appStoreConnectApiKey( keyId: Secret.appStoreKeyIdKey, issuerId: Secret.appStoreIssuerIdKey, From 3be90139e0978608145065b2c14e5e8899d2d66b Mon Sep 17 00:00:00 2001 From: David Date: Fri, 21 Apr 2023 15:05:23 +0700 Subject: [PATCH 4/6] [310] Reposition the connectAPIKey command to be consistent with buildAndUploadToTestFlightLane --- fastlane/Fastfile.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlane/Fastfile.swift b/fastlane/Fastfile.swift index ccba6fe1..09efc269 100644 --- a/fastlane/Fastfile.swift +++ b/fastlane/Fastfile.swift @@ -107,7 +107,6 @@ class Fastfile: LaneFile { desc("Build Production app and upload to App Store") setAppVersion() - AppStoreAuthentication.connectAPIKey() if Secret.bumpAppStoreBuildNumber { bumpAppstoreBuild() } else { @@ -116,6 +115,7 @@ class Fastfile: LaneFile { buildAppStoreLane() + AppStoreAuthentication.connectAPIKey() Distribution.uploadToAppStore() Symbol.uploadToCrashlytics(environment: .production) From 43d95424a4709659a7edb4be225dbd36d1a2dde3 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 21 Apr 2023 15:19:28 +0700 Subject: [PATCH 5/6] [310] Revert --- fastlane/Fastfile.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlane/Fastfile.swift b/fastlane/Fastfile.swift index 09efc269..ccba6fe1 100644 --- a/fastlane/Fastfile.swift +++ b/fastlane/Fastfile.swift @@ -107,6 +107,7 @@ class Fastfile: LaneFile { desc("Build Production app and upload to App Store") setAppVersion() + AppStoreAuthentication.connectAPIKey() if Secret.bumpAppStoreBuildNumber { bumpAppstoreBuild() } else { @@ -115,7 +116,6 @@ class Fastfile: LaneFile { buildAppStoreLane() - AppStoreAuthentication.connectAPIKey() Distribution.uploadToAppStore() Symbol.uploadToCrashlytics(environment: .production) From 68aef4804a282988bac4f9bd4d5c80e3e2916c4c Mon Sep 17 00:00:00 2001 From: David Date: Wed, 26 Apr 2023 11:34:24 +0700 Subject: [PATCH 6/6] [310] Update format code --- fastlane/Constants/Constant.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastlane/Constants/Constant.swift b/fastlane/Constants/Constant.swift index c77b3cee..ae8ddf83 100644 --- a/fastlane/Constants/Constant.swift +++ b/fastlane/Constants/Constant.swift @@ -84,14 +84,14 @@ extension Constant { case production = "Production" var productName: String { "\(Constant.projectName) \(rawValue)".trimmed } - + var scheme: String { switch self { case .staging: return "\(Constant.projectName) \(rawValue)".trimmed case .production: return Constant.projectName.trimmed } } - + var bundleId: String { switch self { case .staging: return Constant.stagingBundleId