Skip to content

Commit

Permalink
Merge pull request #5 from swiftlane-code/di-container
Browse files Browse the repository at this point in the history
Introducing DI Container based object assembly and moving away from yaml configs to in-code configs
  • Loading branch information
vmzhivetyev authored Sep 5, 2023
2 parents 86c8f2b + 7180c6b commit 1063cd8
Show file tree
Hide file tree
Showing 165 changed files with 2,786 additions and 2,761 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlane-code/SwiftlaneCore.git",
"state" : {
"revision" : "f41fee29511809b9b5a9cdc68c327cb1c58e4257",
"version" : "0.9.0"
"revision" : "34d29d337f2b6a160c2e23d05a1b09efd553adeb",
"version" : "0.9.1"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ let package = Package(
.package(url: "https://github.com/nstmrt/SwiftyMocky.git", from: "4.1.1"),
.package(url: "https://github.com/MaxDesiatov/XMLCoder", from: "0.13.1"),
.package(url: "https://github.com/swiftlane-code/AppStoreConnectJWT.git", from: "0.9.0"),
.package(url: "https://github.com/swiftlane-code/SwiftlaneCore.git", from: "0.9.0"),
.package(url: "https://github.com/swiftlane-code/SwiftlaneCore.git", from: "0.9.1"),
.package(url: "https://github.com/tuist/XcodeProj.git", from: "8.7.1"),
.package(url: "https://github.com/MortenGregersen/Bagbutik", from: "3.0.1"),
],
Expand Down
16 changes: 10 additions & 6 deletions Sources/AppStoreConnectAPI/AppStoreConnectIPAUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ public final class AppStoreConnectIPAUploader {
public let authKeyIssuerID: String

/// If you specify a filename, Transporter logs the output to the specified file, as well as to standard out.
public let logFile: AbsolutePath?
public let logDir: AbsolutePath?

/// - Parameter authKeyPath: Path to your `AuthKey_XXXXXX.p8` file.
/// - Parameter authKeyIssuerID: Your issuer ID from the API Keys page in App Store Connect;
/// for example, 57246542-96fe-1a63-e053-0824d011072a.
public init(
authKeyPath: AbsolutePath,
authKeyIssuerID: String,
logFile: AbsolutePath?
logDir: AbsolutePath?
) {
self.authKeyPath = authKeyPath
self.authKeyIssuerID = authKeyIssuerID
self.logFile = logFile
self.logDir = logDir
}
}

Expand Down Expand Up @@ -70,8 +70,12 @@ extension AppStoreConnectIPAUploader: AppStoreConnectIPAUploading {

switch uploader {
case .iTMSTransporter:
config.logFile.map {
try? filesManager.mkdir($0.deletingLastComponent)
let logFile = try config.logDir?.appending(
path: "\(ipaPath.lastComponent.string)_\(Date().full_custom).log"
)

config.logDir.map {
try? filesManager.mkdir($0)
}

let token = try tokenGenerator.token(lifetime: 20 * 60)
Expand All @@ -86,7 +90,7 @@ extension AppStoreConnectIPAUploader: AppStoreConnectIPAUploading {
"-assetFile " + ipaPath.string.quoted,
"-k 100000", // throttle speed is a required option so we set it to 100mbit/s
"-throughput",
config.logFile.map {
logFile.map {
"-o " + $0.string.quoted
},
].compactMap { $0 },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//

import Foundation
import SwiftlaneCore

public extension FileMergeRequestReporter {
/// Create new `FileMergeRequestReporter` instance.
convenience init(
logger: Logging,
filesManager: FSManaging,
reportFilePath: AbsolutePath
) {
self.init(
logger: logger,
filesManager: filesManager,
reportFactory: MergeRequestReportFactory(
captionProvider: MergeRequestReportCaptionProvider(ciToolName: "Swiftlane")
),
reportFilePath: reportFilePath
)
}
}

public class FileMergeRequestReporter: MergeRequestReporting {
public enum Errors: Error, Equatable {
case failsReported(reportURL: String)
}

private let logger: Logging
private let filesManager: FSManaging
private let reportFactory: MergeRequestReportFactoring
private let reportFilePath: AbsolutePath

private var fails: [String] = []
private var warns: [String] = []
private var messages: [String] = []
private var markdowns: [String] = []
private var successes: [String] = []

private var isEmptyReport: Bool {
[fails, warns, messages, markdowns, successes].allSatisfy(\.isEmpty)
}

/// Create new `FileMergeRequestReporter` instance.
public init(
logger: Logging,
filesManager: FSManaging,
reportFactory: MergeRequestReportFactoring,
reportFilePath: AbsolutePath
) {
self.logger = logger
self.filesManager = filesManager
self.reportFactory = reportFactory
self.reportFilePath = reportFilePath
}

public func hasFails() -> Bool {
!fails.isEmpty
}

public func createOrUpdateReport() throws {
let text = reportFactory.reportBody(
fails: fails,
warns: warns,
messages: messages,
markdowns: markdowns,
successes: successes,
invisibleMark: "invisibleMergeRequestNoteMark",
commitSHA: "fakeCommitSHA"
)

logger.verbose("Guardian report: \n" + text.addPrefixToAllLines("\t"))

try filesManager.write(reportFilePath, text: text)

if hasFails() {
let guardianError = Errors.failsReported(reportURL: reportFilePath.string)
logger.logError(guardianError)
throw guardianError
} else {
logger.success("Reported no fails, report url: \(reportFilePath.string)")
}
}

public func warn(_ markdown: String) {
warns.append(markdown)
}

public func fail(_ markdown: String) {
fails.append(markdown)
}

public func message(_ markdown: String) {
messages.append(markdown)
}

public func markdown(_ markdown: String) {
markdowns.append(markdown)
}

public func success(_ markdown: String) {
successes.append(markdown)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,8 @@ import Foundation
import GitLabAPI
import SwiftlaneCore

// sourcery: AutoMockable
public protocol MergeRequestReporting {
func checkEnvironmentCorrect() throws

func createOrUpdateReport() throws

func warn(_ markdown: String)

func fail(_ markdown: String)

func message(_ markdown: String)

func markdown(_ markdown: String)

func success(_ markdown: String)

func hasFails() -> Bool
}

public extension MergeRequestReporter {
/// Create new `MergeRequestReporter` instance.
public extension GitLabMergeRequestReporter {
/// Create new `GitLabMergeRequestReporter` instance.
///
/// - Parameters:
/// - publishEmptyReport: when `false` empty report will not be commented/updated.
Expand All @@ -47,7 +28,7 @@ public extension MergeRequestReporter {
}
}

public class MergeRequestReporter: MergeRequestReporting {
public class GitLabMergeRequestReporter: MergeRequestReporting {
public enum Errors: Error, Equatable {
case failsReported(reportURL: String)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//

// sourcery: AutoMockable
public protocol MergeRequestReporting {
func createOrUpdateReport() throws

func warn(_ markdown: String)

func fail(_ markdown: String)

func message(_ markdown: String)

func markdown(_ markdown: String)

func success(_ markdown: String)

func hasFails() -> Bool
}
2 changes: 1 addition & 1 deletion Sources/Guardian/Tasks/GuardianBaseTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ open class GuardianBaseTask {
public func run() throws {
do {
try executeChecksOnly()
} catch let error as MergeRequestReporter.Errors {
} catch let error as GitLabMergeRequestReporter.Errors {
/// ignore errors produced by MergeRequestReporter
/// because it means we are running ``GuardianBaseTask`` inside ``GuardianBaseTask``
/// and report has already been published.
Expand Down
16 changes: 15 additions & 1 deletion Sources/Networking/Services/NetworkingProgressLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@ import Combine
import Foundation
import SwiftlaneCore

public class NetworkingProgressLogger {
public protocol NetworkingProgressLogging {
func performLoggingProgress<Result>(
description: String,
publisher: AnyPublisher<ProgressOrResult<NetworkingProgress, Result>, NetworkingError>,
timeout: TimeInterval
) throws -> Result

func performLoggingDoubleProgress<Result, Failure>(
description: String,
publisher: AnyPublisher<ProgressOrResult<Double, Result>, Failure>,
timeout: TimeInterval
) throws -> Result
}

public class NetworkingProgressLogger: NetworkingProgressLogging {
private let progressLogger: ProgressLogging

public init(progressLogger: ProgressLogging) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
import Foundation
import SwiftlaneCore

public class CertsInstaller {
public protocol CertsInstalling {
func installCertificatesAndProfiles(config: CertsInstallConfig) throws
-> [(MobileProvision, installPath: AbsolutePath)]
}

public class CertsInstaller: CertsInstalling {
private let logger: Logging

private let repo: CertsRepositoryProtocol
private let atomicInstaller: CertsAtomicInstalling
private let filesManager: FSManaging
private let remoteCertInstaller: RemoteCertificateInstaller
private let remoteCertInstaller: RemoteCertificateInstalling

public init(
logger: Logging,
repo: CertsRepositoryProtocol,
atomicInstaller: CertsAtomicInstalling,
filesManager: FSManaging,
remoteCertInstaller: RemoteCertificateInstaller
remoteCertInstaller: RemoteCertificateInstalling
) {
self.logger = logger
self.repo = repo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
import Foundation
import SwiftlaneCore

public class RemoteCertificateInstaller {
public protocol RemoteCertificateInstalling {
func installCertificate(
from url: URL,
downloadTimeout: TimeInterval,
keychainName: String,
installTimeout: TimeInterval
) throws
}

public class RemoteCertificateInstaller: RemoteCertificateInstalling {
private let logger: Logging
private let shell: ShellExecuting
private let filesManager: FSManaging
Expand Down
4 changes: 2 additions & 2 deletions Sources/Simulator/SimulatorCloner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import SwiftlaneCore
public struct SimulatorCloner {
public let original: SimulatorProtocol
let simulatorProvider: SimulatorProviding
let timeMeasurer: TimeMeasurer
let timeMeasurer: TimeMeasuring

public init(
original: SimulatorProtocol,
simulatorProvider: SimulatorProviding,
timeMeasurer: TimeMeasurer
timeMeasurer: TimeMeasuring
) {
self.original = original
self.simulatorProvider = simulatorProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,14 @@ public struct AddJiraIssueCommentCommandRunner: CommandRunnerProtocol {
public func run(
params: AddJiraIssueCommentCommandParamsAccessing,
commandConfig: AddJiraIssueCommentCommandConfig,
sharedConfig: SharedConfigData,
logger: Logging
sharedConfig: SharedConfigData
) throws {
let environmentValueReader = EnvironmentValueReader()
let gitlabCIEnvironmentReader = GitLabCIEnvironmentReader(environmentValueReading: environmentValueReader)

let issueKeySearcher = IssueKeySearcher(
logger: logger,
issueKeyParser: IssueKeyParser(jiraProjectKey: sharedConfig.values.jiraProjectKey),
gitlabCIEnvironmentReader: gitlabCIEnvironmentReader
)

let taskConfig = AddJiraIssueCommentTask.Config(
text: params.text,
ignoredIssues: commandConfig.ignoredIssues
)

let jiraClient = try JiraAPIClient(
requestsTimeout: sharedConfig.values.jiraRequestsTimeout,
logger: logger
)

let task = AddJiraIssueCommentTask(
logger: logger,
jiraClient: jiraClient,
issueKeySearcher: issueKeySearcher,
config: taskConfig
)

let projectPath = try gitlabCIEnvironmentReader.string(.CI_PROJECT_PATH)
guard sharedConfig.values.availableProjects.isMatching(string: projectPath) else {
logger.warn("Skipped run task about project with path \(projectPath.quoted)")
return
}
let task = TasksFactory.makeAddJiraIssueCommentTask(taskConfig: taskConfig)

try task.run(sharedConfig: sharedConfig.values)
}
Expand Down
3 changes: 0 additions & 3 deletions Sources/Swiftlane/Commands/BuildCommand/BuildAppCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import SwiftlaneCore

public protocol BuildAppCommandParamsAccessing {
var sharedConfigOptions: SharedConfigOptions { get }
var rosettaOption: RosettaGlobalOption { get }

var scheme: String { get }
var buildConfiguration: String { get }
Expand All @@ -21,8 +20,6 @@ public struct BuildAppCommand: ParsableCommand, BuildAppCommandParamsAccessing {

@OptionGroup public var sharedConfigOptions: SharedConfigOptions

@OptionGroup public var rosettaOption: RosettaGlobalOption

@Option(help: "Scheme to build.")
public var scheme: String

Expand Down
Loading

0 comments on commit 1063cd8

Please sign in to comment.