From ceb5a2aab3fa88d29957c2e16deb6c0049db7f1b Mon Sep 17 00:00:00 2001 From: David Date: Thu, 20 Jul 2023 10:21:59 +0700 Subject: [PATCH] [#498] Update fastlane lane: syncCodeSigning and buildAndTest --- fastlane/Fastfile.swift | 109 ++++++++++++++++++----------------- fastlane/Helpers/Match.swift | 33 +++-------- 2 files changed, 66 insertions(+), 76 deletions(-) diff --git a/fastlane/Fastfile.swift b/fastlane/Fastfile.swift index ccba6fe1..3340b285 100644 --- a/fastlane/Fastfile.swift +++ b/fastlane/Fastfile.swift @@ -9,9 +9,9 @@ import Foundation class Fastfile: LaneFile { - + // MARK: - Code signing - + func syncDevelopmentStagingCodeSigningLane() { desc("Sync the Development match signing for the Staging build") Match.syncCodeSigning( @@ -27,7 +27,7 @@ class Fastfile: LaneFile { environment: .production ) } - + func syncAdHocStagingCodeSigningLane() { desc("Sync the Ad Hoc match signing for the Staging build") Match.syncCodeSigning( @@ -35,7 +35,7 @@ class Fastfile: LaneFile { environment: .staging ) } - + func syncAdHocProductionCodeSigningLane() { desc("Sync the Ad Hoc match signing for the Production build") Match.syncCodeSigning( @@ -43,7 +43,7 @@ class Fastfile: LaneFile { environment: .production ) } - + func syncAppStoreCodeSigningLane() { desc("Sync the App Store match signing for the Production build") Match.syncCodeSigning( @@ -51,61 +51,61 @@ class Fastfile: LaneFile { environment: .production ) } - + // MARK: - Build - + func buildAdHocStagingLane() { desc("Build ad-hoc staging") Build.adHoc(environment: .staging) } - + func buildAdHocProductionLane() { desc("Build ad-hoc production") Build.adHoc(environment: .production) } - + func buildAppStoreLane() { desc("Build app store") Build.appStore() } - + // MARK: - Upload builds to Firebase and AppStore - + func buildStagingAndUploadToFirebaseLane() { desc("Build Staging app and upload to Firebase") - + setAppVersion() bumpBuild() - + buildAdHocStagingLane() - + // TODO: - Make release notes Distribution.uploadToFirebase(environment: .staging, releaseNotes: "") - + Symbol.uploadToCrashlytics(environment: .staging) - + Build.saveBuildContextToCI() } - + func buildProductionAndUploadToFirebaseLane() { desc("Build Production app and upload to Firebase") - + setAppVersion() bumpBuild() - + buildAdHocProductionLane() - + // TODO: - Make release notes Distribution.uploadToFirebase(environment: .production, releaseNotes: "") - + Symbol.uploadToCrashlytics(environment: .production) - + Build.saveBuildContextToCI() } - + func buildAndUploadToAppStoreLane() { desc("Build Production app and upload to App Store") - + setAppVersion() AppStoreAuthentication.connectAPIKey() if Secret.bumpAppStoreBuildNumber { @@ -113,76 +113,81 @@ class Fastfile: LaneFile { } else { bumpBuild() } - + buildAppStoreLane() - + Distribution.uploadToAppStore() - + Symbol.uploadToCrashlytics(environment: .production) - + Build.saveBuildContextToCI() } - + func buildAndUploadToTestFlightLane() { desc("Build Production app and upload to TestFlight") - + setAppVersion() bumpBuild() - + buildAppStoreLane() - + AppStoreAuthentication.connectAPIKey() Distribution.uploadToTestFlight() - + Symbol.uploadToCrashlytics(environment: .production) - + Build.saveBuildContextToCI() } - + // MARK: - Test - + func buildAndTestLane() { desc("Build and Test project") + let testDevice = EnvironmentParser.string(key: "test_device") + let devices = !testDevice.isEmpty ? [testDevice] : Constant.devices + + let targets = [ + Constant.testTarget, + Constant.kifUITestTarget + ] + Test.buildAndTest( environment: .staging, - targets: [ - Constant.testTarget, - Constant.kifUITestTarget - ], - devices: Constant.devices + targets: targets, + devices: devices ) } - + func setUpTestProjectLane() { desc("Disable Exempt Encryption") Test.disableExemptEncryption() } - + // MARK: - Register device - + func registerNewDeviceLane() { let deviceName = prompt(text: "Enter the device name:") let deviceUDID = prompt(text: "Enter the device UDID:") - + registerDevice( name: deviceName, udid: deviceUDID, teamId: .userDefined(Constant.appleStagingTeamId) ) - + Match.syncCodeSigning(type: .development, environment: .staging, isForce: true) Match.syncCodeSigning(type: .adHoc, environment: .staging, isForce: true) } - + // MARK: - Utilities - + func cleanUpOutputLane() { desc("Clean up Output") clearDerivedData(derivedDataPath: Constant.outputPath) } - + // MARK: - Private Helper - + private func setAppVersion() { desc("Check if any specific version number in build environment") guard !Constant.manualVersion.isEmpty else { return } @@ -190,7 +195,7 @@ class Fastfile: LaneFile { versionNumber: .userDefined(Constant.manualVersion) ) } - + private func bumpBuild(buildNumber: Int = numberOfCommits()) { desc("Set build number with number of commits") incrementBuildNumber( @@ -198,7 +203,7 @@ class Fastfile: LaneFile { xcodeproj: .userDefined(Constant.projectPath) ) } - + private func bumpAppstoreBuild() { desc("Set build number with App Store latest build") let theLatestBuildNumber = latestTestflightBuildNumber( diff --git a/fastlane/Helpers/Match.swift b/fastlane/Helpers/Match.swift index 2bcdd392..ca22d178 100644 --- a/fastlane/Helpers/Match.swift +++ b/fastlane/Helpers/Match.swift @@ -9,30 +9,15 @@ enum Match { static func syncCodeSigning(type: Constant.BuildType, environment: Constant.Environment, isForce: Bool = false) { - if isCi() { - Keychain.create() - match( - type: type.match, - readonly: .userDefined(!isForce), - appIdentifier: [environment.bundleId], - username: .userDefined(environment.appleUsername), - teamId: .userDefined(environment.appleTeamId), - gitUrl: Constant.matchURL, - keychainName: Constant.keychainName, - keychainPassword: .userDefined(Secret.keychainPassword), - force: .userDefined(isForce) - ) - } else { - match( - type: type.match, - readonly: .userDefined(!isForce), - appIdentifier: [environment.bundleId], - username: .userDefined(environment.appleUsername), - teamId: .userDefined(environment.appleTeamId), - gitUrl: Constant.matchURL, - force: .userDefined(isForce) - ) - } + match( + type: type.match, + readonly: .userDefined(!isForce), + appIdentifier: [environment.bundleId], + username: .userDefined(environment.appleUsername), + teamId: .userDefined(environment.appleTeamId), + gitUrl: Constant.matchURL, + force: .userDefined(isForce) + ) updateCodeSigning(type: type, environment: environment) }