Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 16 additions & 10 deletions Sources/DangerShellExecutor/ShellExecutor.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

public enum SpawnError: Error {
case commandFailed(command: String, exitCode: Int32, stdout: String, stderr: String)
Expand Down Expand Up @@ -62,16 +65,19 @@ public struct ShellExecutor: ShellExecuting {
with: arguments,
environmentVariables: environmentVariables,
outputFile: outputFile)
do {
let pipe = Pipe()
task.standardOutput = pipe
try task.run()

let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
task.waitUntilExit()

task.waitUntilExit()

return String(data: data, encoding: .utf8)!.trimmingCharacters(in: .whitespacesAndNewlines)
return String(data: data, encoding: .utf8)!.trimmingCharacters(in: .whitespacesAndNewlines)
} catch {
return error.localizedDescription
}
}

// Similar to above, but can throw, and throws with most of
Expand All @@ -90,7 +96,7 @@ public struct ShellExecutor: ShellExecuting {
task.standardOutput = stdout
let stderr = Pipe()
task.standardError = stderr
task.launch()
try task.run()

// Pull out the STDOUT as a string because we'll need that regardless
let stdoutData = stdout.fileHandleForReading.readDataToEndOfFile()
Expand Down Expand Up @@ -131,10 +137,10 @@ public struct ShellExecutor: ShellExecuting {
let script = "\(command) \(arguments.joined(separator: " "))" + scriptOutputFile

let task = Process()
task.launchPath = "/bin/sh"
task.executableURL = URL(fileURLWithPath: "/bin/sh")
task.arguments = ["-c", script]
task.environment = mergeEnvs(localEnv: environmentVariables, processEnv: ProcessInfo.processInfo.environment)
task.currentDirectoryPath = FileManager.default.currentDirectoryPath
task.currentDirectoryURL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
return task
}

Expand Down
9 changes: 6 additions & 3 deletions Sources/Runner/Commands/RunDangerJS.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Foundation
import Logger
import RunnerLib
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

func runDangerJSCommandToRunDangerSwift(_ command: DangerCommand, logger: Logger) throws -> Int32 {
guard let dangerJS = try? getDangerCommandPath(logger: logger) else {
Expand All @@ -22,7 +25,7 @@ func runDangerJSCommandToRunDangerSwift(_ command: DangerCommand, logger: Logger

let proc = Process()
proc.environment = ProcessInfo.processInfo.environment
proc.launchPath = dangerJS
proc.executableURL = URL(fileURLWithPath: dangerJS)

let dangerOptionsIndexes = DangerSwiftOption.allCases
.compactMap { option -> (DangerSwiftOption, Int)? in
Expand Down Expand Up @@ -62,8 +65,8 @@ func runDangerJSCommandToRunDangerSwift(_ command: DangerCommand, logger: Logger
proc.standardOutput = standardOutput
proc.standardError = standardOutput

logger.debug("Running: \(proc.launchPath!) \(proc.arguments!.joined(separator: " ")) ")
proc.launch()
logger.debug("Running: \(proc.executableURL!) \(proc.arguments!.joined(separator: " ")) ")
try proc.run()
proc.waitUntilExit()

return proc.terminationStatus
Expand Down
9 changes: 6 additions & 3 deletions Sources/Runner/Commands/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import DangerShellExecutor
import Foundation
import Logger
import RunnerLib
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

// swiftlint:disable:next function_body_length
func runDanger(version dangerSwiftVersion: String, logger: Logger) throws {
Expand Down Expand Up @@ -152,19 +155,19 @@ func runDanger(version dangerSwiftVersion: String, logger: Logger) throws {

// Create a process to eval the Swift file
let proc = Process()
proc.launchPath = swiftC
proc.executableURL = URL(fileURLWithPath: swiftC)
proc.arguments = args
let standardOutput = FileHandle.standardOutput
if let cwdOptionIndex = CommandLine.arguments.firstIndex(of: DangeSwiftRunnerOption.cwd.rawValue),
(cwdOptionIndex + 1) < CommandLine.arguments.count,
let directoryURL = URL(string: CommandLine.arguments[cwdOptionIndex + 1])
{
proc.currentDirectoryPath = directoryURL.absoluteString
proc.currentDirectoryURL = directoryURL
Comment on lines -162 to +165
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @f-meloni @417-72KI, this is a breaking change and needs a fix.

I prepared a PR to fix this issue, please have a look and review it. We would be grateful if we could include the fix in one of the next versions 🙏🙇.

Here is the PR: #650

Let me know if you need anything from me.

}
proc.standardOutput = standardOutput
proc.standardError = standardOutput

proc.launch()
try proc.run()
proc.waitUntilExit()

logger.debug("Completed evaluation")
Expand Down