Skip to content

Commit 3261c11

Browse files
authored
Merge branch 'master' into review-before-submmitted
2 parents b8721e6 + b22f43c commit 3261c11

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
## Master
1515

1616
- Fix: `GitHub.Review.submittedAt` may be `nil` [@417-72KI][] - [#624](https://github.com/danger/swift/pull/624)
17+
- Drain stdout while shell commands are running to prevent execution from locking up if there's too much output [@jflan-dd][] - [#614](https://github.com/danger/swift/pull/614)
1718

1819
## 3.20.0
20+
1921
- Remove deprecated `lint` function with `lintAllFiles` flag [@417-72KI][] - [#622](https://github.com/danger/swift/pull/622)
2022
- Updated Swift 6 build process: Danger files moved to .build/debug/Modules, and SwiftFormat module map conflict resolved by adjusting the Swift import search path. [@abhi-m-simformsolutons][] -[#626](https://github.com/danger/swift/pull/626)
2123

Sources/Danger/Plugins/SwiftLint/SwiftLint.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ extension SwiftLint {
185185
var arguments = arguments
186186

187187
if let directory = directory {
188-
arguments.append("--path \"\(directory)\"")
188+
arguments.append(directory)
189189
}
190190

191191
return swiftlintViolations(swiftlintPath: swiftlintPath,

Sources/DangerShellExecutor/ShellExecutor.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ public struct ShellExecutor: ShellExecuting {
6161
let pipe = Pipe()
6262
task.standardOutput = pipe
6363
task.launch()
64-
task.waitUntilExit()
6564

6665
let data = pipe.fileHandleForReading.readDataToEndOfFile()
66+
67+
task.waitUntilExit()
68+
6769
return String(data: data, encoding: .utf8)!.trimmingCharacters(in: .whitespacesAndNewlines)
6870
}
6971

@@ -83,19 +85,22 @@ public struct ShellExecutor: ShellExecuting {
8385
let stderr = Pipe()
8486
task.standardError = stderr
8587
task.launch()
86-
task.waitUntilExit()
8788

8889
// Pull out the STDOUT as a string because we'll need that regardless
8990
let stdoutData = stdout.fileHandleForReading.readDataToEndOfFile()
9091
let stdoutString = String(data: stdoutData, encoding: .utf8)!
9192

93+
// Read from STDERR to ensure the `Pipe` does not fill up
94+
let stderrData = stderr.fileHandleForReading.readDataToEndOfFile()
95+
96+
task.waitUntilExit()
97+
9298
// 0 is no problems in unix land
9399
if task.terminationStatus == 0 {
94100
return stdoutString.trimmingCharacters(in: .whitespacesAndNewlines)
95101
}
96102

97103
// OK, so it failed, raise a new error with all the useful metadata
98-
let stderrData = stderr.fileHandleForReading.readDataToEndOfFile()
99104
let stderrString = String(data: stderrData, encoding: .utf8)!
100105

101106
throw SpawnError.commandFailed(command: command,

Tests/DangerTests/SwiftLint/DangerSwiftLintTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ final class DangerSwiftLintTests: XCTestCase {
268268
XCTAssertNotNil(swiftlintCommand)
269269
XCTAssertEqual(swiftlintCommand!.environmentVariables.count, 0)
270270
XCTAssertFalse(swiftlintCommand!.environmentVariables.values.contains { $0.contains("Tests/SomeFile.swift") })
271-
XCTAssertTrue(swiftlintCommand!.arguments.contains("--path \"Tests\""))
271+
XCTAssertEqual(swiftlintCommand!.arguments.last, directory)
272272
}
273273

274274
func testFiltersOnSwiftFiles() {

0 commit comments

Comments
 (0)