Skip to content

Commit

Permalink
Custom Xcode version
Browse files Browse the repository at this point in the history
  • Loading branch information
onmyway133 committed Feb 17, 2022
1 parent 6b8fadf commit 4f9a573
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 31 deletions.
11 changes: 7 additions & 4 deletions Examples/CLI/CLI/Script.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ struct Script {
private static func deployMyApp() async throws {
var workflow = Workflow()
workflow.directory = Settings.fs
.homeDirectory()
.homeDirectory
.appendingPathComponent("XcodeProject2/swiftlane/Examples/MyApp")
workflow.xcodeApp = Settings.fs.applicationsDirectory.appendingPathComponent("Xcode.app")

let build = Build()
build.project("MyApp")
build.allowProvisioningUpdates()
build.destination(platform: .iOSSimulator, name: "iPhone 13")
build.workflow = workflow
// try await build.run()
try await build.run()

guard
let issuerId = Settings.env["ASC_ISSUER_ID"],
Expand All @@ -42,19 +43,21 @@ struct Script {
)
)

/*
let keychain = try await Keychain.create(
path: Keychain.Path(
rawValue: Settings.fs
.downloadsDirectory()
.downloadsDirectory
.appendingPathComponent("custom.keychain")),
password: "keychain_password"
)
try await keychain.unlock()
try await keychain.import(
certificateFile: Settings.fs
.downloadsDirectory()
.downloadsDirectory
.appendingPathComponent("abcpass.p12"),
certificatePassword: "123"
)
*/
}
}
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,53 @@ struct Script {
static func main() async throws {
try await deployMyApp()
}

private static func deployMyApp() async throws {
var workflow = Workflow()
workflow.directory = Settings.fs
.homeDirectory()
.appendingPathComponent("Projects/swiftlane/Examples/MyApp")

workflow.xcodeApp = URL(string: "/Applications/Xcode.app")

let build = Build()
build.project("MyApp")
build.allowProvisioningUpdates()
build.destination(platform: .iOSSimulator, name: "iPhone 13")
build.workflow = workflow
try await build.run()

guard
let issuerId = Settings.env["ASC_ISSUER_ID"],
let privateKeyId = Settings.env["ASC_PRIVATE_KEY_ID"],
let privateKey = Settings.env["ASC_PRIVATE_KEY"]
else { return }

let asc = try ASC(
credential: AppStoreConnect.Credential(
issuerId: issuerId,
privateKeyId: privateKeyId,
privateKey: privateKey
)
)

try await asc.fetchCertificates()
try await asc.fetchProvisioningProfiles()

let keychain = try await Keychain.create(
path: Keychain.Path(
rawValue: Settings.fs
.downloadsDirectory
.appendingPathComponent("custom.keychain")),
password: "keychain_password"
)
try await keychain.unlock()
try await keychain.import(
certificateFile: Settings.fs
.downloadsDirectory
.appendingPathComponent("abcpass.p12"),
certificatePassword: "123"
)

}
}
```
Expand Down Expand Up @@ -85,6 +102,7 @@ struct Script {
- [x] Fetch provisioning profiles
- [x] Save certificates into file system
- [x] Save profiles into file system
- [x] Install provisioning profile

#### Keychain

Expand All @@ -97,6 +115,10 @@ struct Script {
- [ ] Boot a simulator
- [ ] Update and style simulator

#### Xcode

- [x] Print current Xcode path

### macOS
- [x] Notarize: notarize project
- [ ] MakeDMG: package as DMG
Expand Down
17 changes: 17 additions & 0 deletions Sources/Swiftlane/Actions/iOS/ASC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,21 @@ public extension ASC {

try data.write(to: toFile.ensuringExtension("cer"))
}

func install(
profile: Profile
) async throws {
guard
let uuid = profile.attributes?.uuid
else {
throw SwiftlaneError.invalid("uuid")
}

try await save(
profile: profile,
toFile: Settings.fs.provisioningProfilesDirectory
.appendingPathComponent(uuid)
.appendingPathExtension("mobileprovision")
)
}
}
2 changes: 1 addition & 1 deletion Sources/Swiftlane/Actions/iOS/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class Archive {

args.flag("archive")
_ = try Settings.cli.run(
program: "xcodebuild",
program: xcodebuild(),
argument: args.toString(),
currentDirectoryURL: workflow?.directory,
processHandler: XcodeBuildProcessHandler()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftlane/Actions/iOS/Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class Build {
}

_ = try Settings.cli.run(
program: "xcodebuild",
program: xcodebuild(),
argument: args.toString(),
currentDirectoryURL: workflow?.directory,
processHandler: XcodeBuildProcessHandler()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftlane/Actions/iOS/ExportArchive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class ExportArchive {
args.flag("-exportArchive")

_ = try Settings.cli.run(
program: "xcodebuild",
program: xcodebuild(),
argument: args.toString(),
currentDirectoryURL: workflow?.directory,
processHandler: XcodeBuildProcessHandler()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftlane/Actions/iOS/Keychain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public extension Keychain {

public static var login: Path {
Path(
rawValue: Settings.fs.keychainsDirectory()
rawValue: Settings.fs.keychainsDirectory
.appendingPathComponent("login.keychain")
)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Swiftlane/Actions/iOS/Screenshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final class Screenshot {
attachmentFilter: { _ in true }
)

let destination = saveFolder ?? Settings.fs.downloadsDirectory()
let destination = saveFolder ?? Settings.fs.downloadsDirectory
try XCPParser().extractAttachments(
xcresultPath: xcresultPath(),
destination: destination.path,
Expand Down
9 changes: 1 addition & 8 deletions Sources/Swiftlane/Actions/iOS/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,7 @@ public final class Test {
}

_ = try Settings.cli.run(
program: "xcodebuild",
argument: args.toString(),
currentDirectoryURL: workflow?.directory,
processHandler: XcodeBuildProcessHandler()
)

_ = try Settings.cli.run(
program: "xcodebuild",
program: xcodebuild(),
argument: args.toString(),
currentDirectoryURL: workflow?.directory,
processHandler: XcodeBuildProcessHandler()
Expand Down
23 changes: 23 additions & 0 deletions Sources/Swiftlane/Actions/iOS/Xcode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Xcode.swift
// Swiftlane
//
// Created by Khoa on 17/02/2022.
//

import Foundation

public struct Xcode {
public init() {}

public func currentPath() async throws -> String {
var args = Args()
args.flag("-print-path")

return try Settings.cli.run(
program: "xcode-select",
argument: args.toString(),
processHandler: DefaultProcessHandler()
)
}
}
32 changes: 23 additions & 9 deletions Sources/Swiftlane/Library/Core/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public struct FileSystem {
FileManager.default.fileExists(atPath: url.path)
}

public func homeDirectory() -> URL {
FileManager.default.homeDirectoryForCurrentUser
}

public func currentDirectory() async throws -> URL {
let process = Process()
process.launchPath = "/bin/pwd"
Expand All @@ -42,14 +38,32 @@ public struct FileSystem {
return url
}

public func downloadsDirectory() -> URL {
homeDirectory()
public var homeDirectory: URL {
FileManager.default.homeDirectoryForCurrentUser
}

public var downloadsDirectory: URL {
homeDirectory
.appendingPathComponent("Downloads")
}

public func keychainsDirectory() -> URL {
homeDirectory()
.appendingPathComponent("Library/Keychains")
public var libraryDirectory: URL {
homeDirectory
.appendingPathComponent("Library")
}

public var applicationsDirectory: URL {
URL(string: "/Applications")!
}

public var keychainsDirectory: URL {
libraryDirectory
.appendingPathComponent("Keychains")
}

public var provisioningProfilesDirectory: URL {
libraryDirectory
.appendingPathComponent("MobileDevice/Provisioning Profiles")
}
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Swiftlane/Library/Core/Workflow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation

public struct Workflow {
public var directory: URL?
public var xcodeApp: URL?

public init() {}
}
13 changes: 13 additions & 0 deletions Sources/Swiftlane/Library/Tools/Xcodebuild.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Foundation

public protocol UseXcodebuild: AnyObject {
var args: Args { get set }
var workflow: Workflow? { get }
}

public extension UseXcodebuild {
Expand Down Expand Up @@ -102,6 +103,18 @@ public extension UseXcodebuild {
args["-testPlan"] = file.path
.deletingPathExtension("xctestplan")
}

func xcodebuild() -> String {
guard
let xcodeApp = workflow?.xcodeApp
else {
return "xcodebuild"
}

return xcodeApp
.appendingPathComponent("Contents/Developer/usr/bin/xcodebuild")
.path
}
}

public enum Xcodebuild {
Expand Down

0 comments on commit 4f9a573

Please sign in to comment.