Merge pull request #3 from f-meloni/swift_scripts
Swift scripts support
This commit is contained in:
commit
d05a60493b
|
@ -26,6 +26,8 @@ if FileManager.default.fileExists(atPath: rocketYamlPath) {
|
|||
stepsDictionary = loadedDictionary
|
||||
} else if let rocketConfig = getPackageConfig()["rocket"] as? [String: Any] {
|
||||
stepsDictionary = rocketConfig
|
||||
} else {
|
||||
logger.logError("Steps not found")
|
||||
}
|
||||
|
||||
let versionExporter = VersionExporter()
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
import Foundation
|
||||
import Logger
|
||||
|
||||
final class SwiftScriptExecutor: DefaultExecutor<SwiftScriptParameters> {
|
||||
lazy var fileManager: FileManager = .default
|
||||
lazy var processLauncher: ProcessLaunching = ProcessLauncher()
|
||||
|
||||
override func executeStep(version: String, logger: Logger) {
|
||||
guard let scriptPath = parameters.scriptPath else {
|
||||
logger.logError("Invalid script path for the Swift script step")
|
||||
return
|
||||
}
|
||||
|
||||
let supportedSwiftCPaths = ["/usr/bin/swiftc", "/home/travis/.swiftenv/shims/swiftc"]
|
||||
|
||||
let swiftCPath = supportedSwiftCPaths.first { fileManager.fileExists(atPath: $0) }
|
||||
let swiftC = swiftCPath ?? "swiftc"
|
||||
let args = [
|
||||
"--driver-mode=swift",
|
||||
scriptPath,
|
||||
version,
|
||||
]
|
||||
|
||||
logger.logInfo("Running: \(swiftC) \(args.joined(separator: " "))")
|
||||
|
||||
let process = Process()
|
||||
process.launchPath = swiftC
|
||||
process.arguments = args
|
||||
|
||||
let standardOutput = FileHandle.standardOutput
|
||||
process.standardOutput = standardOutput
|
||||
process.standardError = standardOutput
|
||||
|
||||
processLauncher.launchProcess(process: process)
|
||||
}
|
||||
}
|
||||
|
||||
protocol ProcessLaunching {
|
||||
func launchProcess(process: Process)
|
||||
}
|
||||
|
||||
struct ProcessLauncher: ProcessLaunching {
|
||||
func launchProcess(process: Process) {
|
||||
process.launch()
|
||||
process.waitUntilExit()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
struct SwiftScriptParameters: StepParameters {
|
||||
let scriptPath: String?
|
||||
|
||||
enum CodingKeys: String {
|
||||
case scriptPath = "script_path"
|
||||
}
|
||||
|
||||
init(dictionary: [String: Any]?) {
|
||||
scriptPath = dictionary?[CodingKeys.scriptPath]
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ public enum Step: String {
|
|||
case gitAdd = "git_add"
|
||||
case hideDependencies = "hide_dev_dependencies"
|
||||
case unhideDependencies = "unhide_dev_dependencies"
|
||||
case swiftScript = "swift_script"
|
||||
|
||||
func executor(dictionary: [String: Any]?) -> StepExecutor {
|
||||
return executorType.init(dictionary: dictionary)
|
||||
|
@ -28,6 +29,8 @@ public enum Step: String {
|
|||
return HideDevDependenciesExecutor.self
|
||||
case .unhideDependencies:
|
||||
return UnhideDevDependenciesExecutor.self
|
||||
case .swiftScript:
|
||||
return SwiftScriptExecutor.self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
import Logger
|
||||
import Nimble
|
||||
@testable import RocketLib
|
||||
import XCTest
|
||||
|
||||
final class SwiftScriptExecutorTests: XCTestCase {
|
||||
func testItCreatesTheCorrectProcess() {
|
||||
let testPath = "TestPath.swift"
|
||||
let executor = SwiftScriptExecutor(dictionary: ["script_path": testPath])
|
||||
|
||||
executor.fileManager = DummyFileManager()
|
||||
let processLauncher = SpyProcessLauncher()
|
||||
executor.processLauncher = processLauncher
|
||||
|
||||
executor.executeStep(version: "1.0.0", logger: Logger.testLogger)
|
||||
|
||||
expect(processLauncher.receivedProcess?.launchPath) == "/usr/bin/swiftc"
|
||||
expect(processLauncher.receivedProcess?.arguments) == [
|
||||
"--driver-mode=swift",
|
||||
testPath,
|
||||
"1.0.0",
|
||||
]
|
||||
}
|
||||
|
||||
func testItDoesntCreateTheProcessIfThereIsNoScriptPath() {
|
||||
let executor = SwiftScriptExecutor(dictionary: nil)
|
||||
let processLauncher = SpyProcessLauncher()
|
||||
executor.processLauncher = processLauncher
|
||||
|
||||
executor.executeStep(version: "1.0.0", logger: Logger.testLogger)
|
||||
|
||||
expect(processLauncher.receivedProcess?.launchPath).to(beNil())
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate class DummyFileManager: FileManager {
|
||||
override func fileExists(atPath _: String) -> Bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate class SpyProcessLauncher: ProcessLaunching {
|
||||
var receivedProcess: Process?
|
||||
|
||||
func launchProcess(process: Process) {
|
||||
receivedProcess = process
|
||||
}
|
||||
}
|
|
@ -54,6 +54,13 @@ extension StepsParserTests {
|
|||
]
|
||||
}
|
||||
|
||||
extension SwiftScriptExecutorTests {
|
||||
static let __allTests = [
|
||||
("testItCreatesTheCorrectProcess", testItCreatesTheCorrectProcess),
|
||||
("testItDoesntCreateTheProcessIfThereIsNoScriptPath", testItDoesntCreateTheProcessIfThereIsNoScriptPath),
|
||||
]
|
||||
}
|
||||
|
||||
extension TagExecutorTests {
|
||||
static let __allTests = [
|
||||
("testItSendsTheCorrectScriptToTheScriptLauncher", testItSendsTheCorrectScriptToTheScriptLauncher),
|
||||
|
@ -85,6 +92,7 @@ extension VersionExporterTests {
|
|||
testCase(PushExecutorTests.__allTests),
|
||||
testCase(ScriptExecutorTests.__allTests),
|
||||
testCase(StepsParserTests.__allTests),
|
||||
testCase(SwiftScriptExecutorTests.__allTests),
|
||||
testCase(TagExecutorTests.__allTests),
|
||||
testCase(UnhideDevDependenciesExecutorTests.__allTests),
|
||||
testCase(VersionExporterTests.__allTests),
|
||||
|
|
Loading…
Reference in New Issue