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
1320 ) {
1420 self.comparison = baseline.map(BaselineComparison.init)
1520 self.modules = ModuleTotals.grouping(files)
1620 self.tests = tests
1720 self.commit = commit
1820 }
19
2020 public var markdown: String {
2137 let total = LineSummary(adding: modules.map(\.lines))
2220 var lines = [commit.map { "### Coverage at \($0)" } ?? "### Coverage", ""]
2320 if let tests {
245 lines.append(
255 "**\(tests.totalText)**: \(groupingDigits(tests.passed)) passed, "
265 + "\(groupingDigits(tests.failed)) failed, \(groupingDigits(tests.skipped)) skipped."
275 )
285 }
2920 let totalChange =
3020 comparison.map { ", \($0.changeOfTotal(now: total).text) since the baseline" } ?? ""
3120 lines.append(
3220 "Line coverage: **\(total.percentText)** "
3320 + "(\(groupingDigits(total.covered)) of \(groupingDigits(total.count)) lines)"
3420 + totalChange + ".")
3520 lines += [
3620 "",
3720 "| Module | Line coverage |\(comparison == nil ? "" : " Change |") Missed | Lines |",
3820 comparison == nil
3920 ? "| --- | ---: | ---: | ---: |" : "| --- | ---: | ---: | ---: | ---: |",
4020 ]
4137 for module in modules {
4237 let missed = module.lines.count - module.lines.covered
4337 let changeCell =
4437 comparison.map { " \($0.change(ofModule: module.name, now: module.lines).text) |" }
4537 ?? ""
4637 lines.append(
4737 "| \(module.name) | \(module.lines.percentText) |\(changeCell) "
4837 + "\(groupingDigits(missed)) | \(groupingDigits(module.lines.count)) |")
4937 }
5020 return lines.joined(separator: "\n") + "\n"
5120 }
52}