Skip to content

Commit df985d7

Browse files
authored
YAML diagnostics collector should have stable output (#295)
YAML diagnostics collector should have stable output ### Motivation Fixes #294. Since we're running generation in parallel now, the order of diagnostics depends on the racing of the cores, resulting in unstable output. ### Modifications Sort the diagnostics before writing them to file, making the output stable again. ### Result Stable YAML diagnostics file. ### Test Plan N/A, the order isn't significant, so we're not testing the details of the sorting function, we just care about it being stable. Reviewed by: dnadoba Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (compatibility test) - Build finished. ✔︎ pull request validation (docc test) - Build finished. ✔︎ pull request validation (integration test) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. #295
1 parent a359eab commit df985d7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Sources/swift-openapi-generator/YamlFileDiagnosticsCollector.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ final class _YamlFileDiagnosticsCollector: DiagnosticCollector, @unchecked Senda
4848
func finalize() throws {
4949
lock.lock()
5050
defer { lock.unlock() }
51-
let uniqueMessages = Set(diagnostics.map(\.message)).sorted()
51+
let sortedDiagnostics = diagnostics.sorted(by: { a, b in
52+
a.description < b.description
53+
})
54+
let uniqueMessages = Set(sortedDiagnostics.map(\.message)).sorted()
5255
let encoder = YAMLEncoder()
5356
encoder.options.sortKeys = true
5457
let container = _DiagnosticsYamlFileContent(
5558
uniqueMessages: uniqueMessages,
56-
diagnostics: diagnostics
59+
diagnostics: sortedDiagnostics
5760
)
5861
try encoder
5962
.encode(container)

0 commit comments

Comments
 (0)