Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Sources/VariantsCore/Factory/iOS/XCConfigFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,15 @@ class XCConfigFactory: XCFactory {
else { return }

let isDistribution = exportMethod == .appstore || exportMethod == .enterprise
let certType = isDistribution ? "Distribution" : "Development"

signingSettings[PListKey.provisioningProfile] = "$(V_MATCH_PROFILE)"
signingSettings[PListKey.codeSignIdentity] = "Apple \(certType): \(teamName) (\(teamID))"

if let fetchedSigningIdentity = signing.codeSigningIdentity {
signingSettings[PListKey.codeSignIdentity] = fetchedSigningIdentity
} else {
let certType = isDistribution ? "Distribution" : "Development"
signingSettings[PListKey.codeSignIdentity] = "Apple \(certType): \(teamName) (\(teamID))"
}
}

let xcodeFactory = XcodeProjFactory()
Expand Down Expand Up @@ -250,8 +256,13 @@ class XCConfigFactory: XCFactory {
else { return }

let isDistribution = exportMethod == .appstore || exportMethod == .enterprise
let certType = isDistribution ? "Distribution" : "Development"
signingSettings[PListKey.codeSignIdentity] = "Apple \(certType): \(teamName) (\(teamID))"

if let fetchedSigningIdentity = signing.codeSigningIdentity {
signingSettings[PListKey.codeSignIdentity] = fetchedSigningIdentity
} else {
let certType = isDistribution ? "Distribution" : "Development"
signingSettings[PListKey.codeSignIdentity] = "Apple \(certType): \(teamName) (\(teamID))"
}
}

let xcodeFactory = XcodeProjFactory()
Expand Down
30 changes: 30 additions & 0 deletions Sources/VariantsCore/Schemas/iOS/iOSSigning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ struct iOSSigning: Codable, Equatable {
let exportMethod: ExportMethod?
let matchURL: String?
let style: SigningStyle

var codeSigningIdentity: String? {
guard let teamID = teamID else { return nil }

return fetchSigningCertificate(for: teamID)
}

enum CodingKeys: String, CodingKey {
case teamName = "team_name"
Expand Down Expand Up @@ -115,3 +121,27 @@ extension iOSSigning {
return signing
}
}

extension iOSSigning {
private func fetchSigningCertificate(for teamId: String) -> String? {
do {
let output = try Bash("security", arguments: "find-identity", "-v", "-p", "codesigning")
.capture()

guard let output else { return nil }
let lines = output.split(separator: "\n")

let matches = lines.compactMap { line -> String? in
guard line.contains(teamId) else { return nil }

let components = line.split(separator: "\"", maxSplits: 2, omittingEmptySubsequences: false)
guard components.count > 1 else { return nil }

return String(components[1])
}
return matches.first
} catch {
return nil
}
}
}