1/// The Markdown CI appends to the GitHub Actions job summary: test counts, total line
2/// coverage and a row per module.
3public struct JobSummary: Sendable {
4 private let modules: [ModuleTotals]
5 private let tests: TestCounts?
6 private let commit: String?
7 private let comparison: BaselineComparison?
8
9 /// - Parameter baseline: an earlier run to compare with; with it, the total line and
10 /// the module table show the change since then.
11 public init(
12 files: [FileTotals], tests: TestCounts?, commit: String?, baseline: RunTotals? = nil
1323 ) {
1423 self.comparison = baseline.map(BaselineComparison.init)
1523 self.modules = ModuleTotals.grouping(files)
1623 self.tests = tests
1723 self.commit = commit
1823 }
19
2023 public var markdown: String {
2143 let total = LineSummary(adding: modules.map(\.lines))
2223 var lines = [commit.map { "### Coverage at \($0)" } ?? "### Coverage", ""]
2323 if let tests {
247 lines.append(
257 "**\(tests.totalText)**: \(groupingDigits(tests.passed)) passed, "
267 + "\(groupingDigits(tests.failed)) failed, \(groupingDigits(tests.skipped)) skipped."
277 )
287 }
2923 let totalChange =
3023 comparison.map { ", \($0.changeOfTotal(now: total).text) since the baseline" } ?? ""
3123 lines.append(
3223 "Line coverage: **\(total.percentText)** "
3323 + "(\(groupingDigits(total.covered)) of \(groupingDigits(total.count)) lines)"
3423 + totalChange + ".")
3523 lines += [
3623 "",
3723 "| Module | Line coverage |\(comparison == nil ? "" : " Change |") Missed | Lines |",
3823 comparison == nil
3923 ? "| --- | ---: | ---: | ---: |" : "| --- | ---: | ---: | ---: | ---: |",
4023 ]
4143 for module in modules {
4243 let missed = module.lines.count - module.lines.covered
4343 let changeCell =
4443 comparison.map { " \($0.change(ofModule: module.name, now: module.lines).text) |" }
4543 ?? ""
4643 lines.append(
4743 "| \(module.name) | \(module.lines.percentText) |\(changeCell) "
4843 + "\(groupingDigits(missed)) | \(groupingDigits(module.lines.count)) |")
4943 }
5023 return lines.joined(separator: "\n") + "\n"
5123 }
52}