| 1 | | /// The Markdown CI appends to the GitHub Actions job summary: test counts, total line |
| 2 | | /// coverage and a row per module. |
| 3 | | public 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 |
| 13 | 23 | ) { |
| 14 | 23 | self.comparison = baseline.map(BaselineComparison.init) |
| 15 | 23 | self.modules = ModuleTotals.grouping(files) |
| 16 | 23 | self.tests = tests |
| 17 | 23 | self.commit = commit |
| 18 | 23 | } |
| 19 | | |
| 20 | 23 | public var markdown: String { |
| 21 | 43 | let total = LineSummary(adding: modules.map(\.lines)) |
| 22 | 23 | var lines = [commit.map { "### Coverage at \($0)" } ?? "### Coverage", ""] |
| 23 | 23 | if let tests { |
| 24 | 7 | lines.append( |
| 25 | 7 | "**\(tests.totalText)**: \(groupingDigits(tests.passed)) passed, " |
| 26 | 7 | + "\(groupingDigits(tests.failed)) failed, \(groupingDigits(tests.skipped)) skipped." |
| 27 | 7 | ) |
| 28 | 7 | } |
| 29 | 23 | let totalChange = |
| 30 | 23 | comparison.map { ", \($0.changeOfTotal(now: total).text) since the baseline" } ?? "" |
| 31 | 23 | lines.append( |
| 32 | 23 | "Line coverage: **\(total.percentText)** " |
| 33 | 23 | + "(\(groupingDigits(total.covered)) of \(groupingDigits(total.count)) lines)" |
| 34 | 23 | + totalChange + ".") |
| 35 | 23 | lines += [ |
| 36 | 23 | "", |
| 37 | 23 | "| Module | Line coverage |\(comparison == nil ? "" : " Change |") Missed | Lines |", |
| 38 | 23 | comparison == nil |
| 39 | 23 | ? "| --- | ---: | ---: | ---: |" : "| --- | ---: | ---: | ---: | ---: |", |
| 40 | 23 | ] |
| 41 | 43 | for module in modules { |
| 42 | 43 | let missed = module.lines.count - module.lines.covered |
| 43 | 43 | let changeCell = |
| 44 | 43 | comparison.map { " \($0.change(ofModule: module.name, now: module.lines).text) |" } |
| 45 | 43 | ?? "" |
| 46 | 43 | lines.append( |
| 47 | 43 | "| \(module.name) | \(module.lines.percentText) |\(changeCell) " |
| 48 | 43 | + "\(groupingDigits(missed)) | \(groupingDigits(module.lines.count)) |") |
| 49 | 43 | } |
| 50 | 23 | return lines.joined(separator: "\n") + "\n" |
| 51 | 23 | } |
| 52 | | } |