Skip to content

Commit

Permalink
[#498] Update fastlane lane: syncCodeSigning and buildAndTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ducbm051291 committed Jul 20, 2023
1 parent 3cab6c7 commit ceb5a2a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 76 deletions.
109 changes: 57 additions & 52 deletions fastlane/Fastfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -27,178 +27,183 @@ class Fastfile: LaneFile {
environment: .production
)
}

func syncAdHocStagingCodeSigningLane() {
desc("Sync the Ad Hoc match signing for the Staging build")
Match.syncCodeSigning(
type: .adHoc,
environment: .staging
)
}

func syncAdHocProductionCodeSigningLane() {
desc("Sync the Ad Hoc match signing for the Production build")
Match.syncCodeSigning(
type: .adHoc,
environment: .production
)
}

func syncAppStoreCodeSigningLane() {
desc("Sync the App Store match signing for the Production build")
Match.syncCodeSigning(
type: .appStore,
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 {
bumpAppstoreBuild()
} 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 }
incrementVersionNumber(
versionNumber: .userDefined(Constant.manualVersion)
)
}

private func bumpBuild(buildNumber: Int = numberOfCommits()) {
desc("Set build number with number of commits")
incrementBuildNumber(
buildNumber: .userDefined(String(buildNumber)),
xcodeproj: .userDefined(Constant.projectPath)
)
}

private func bumpAppstoreBuild() {
desc("Set build number with App Store latest build")
let theLatestBuildNumber = latestTestflightBuildNumber(
Expand Down
33 changes: 9 additions & 24 deletions fastlane/Helpers/Match.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit ceb5a2a

Please sign in to comment.