ciSummaryLine function

String ciSummaryLine({
  1. required List<String> stages,
  2. required List<CiOutcome> outcomes,
  3. required Duration elapsed,
  4. required String runDir,
  5. required String relativeTo,
})

The single line every run ends with. One line — a person reading the end of a terminal and a script reading the last line of output get the same answer: green or red, and for each red, the log that holds the finding.

Implementation

String ciSummaryLine({
  required List<String> stages,
  required List<CiOutcome> outcomes,
  required Duration elapsed,
  required String runDir,
  required String relativeTo,
}) {
  String rel(String path) => p.relative(path, from: relativeTo);
  final red = [
    for (final o in outcomes)
      if (!o.ok) o,
  ];
  final time = formatCiDuration(elapsed);
  if (outcomes.isEmpty) {
    return 'CI RED: no step ran (${stages.join(' ')}) in $time';
  }
  final skipped = outcomes.where((o) => o.skipped).length;
  final skips = skipped == 0 ? '' : ', $skipped skipped';
  if (red.isEmpty) {
    final steps = outcomes.length == 1 ? '1 step' : '${outcomes.length} steps';
    return 'CI GREEN: ${stages.join(' ')} — $steps, 0 red'
        '$skips, in $time — logs ${rel(runDir)}';
  }
  final named = red.map((o) => '${o.label} (${rel(o.logPath)})').join('; ');
  return 'CI RED: ${red.length} of ${outcomes.length} steps red — $named — '
      'in $time';
}