runWithConfig static method
Runs the stages with the reporters chosen by the config, and returns the outcome
The command is the name of the build_pipe command, e.g. build
Implementation
static Future<PipeRunResult> runWithConfig(
BPConfig config, {
required String command,
required List<PipeStage> stages,
}) async {
List<PipeReporter> reporters = [];
LogFileReporter? logReporter;
String? logFilePath;
if (config.generateLog) {
(LogFileReporter?, String?) opened = LogFileReporter.open(config.logFile);
if (opened.$2 != null) {
Console.logWarning("The log file could not be created, so this run will not be logged -> ${opened.$2}");
} else {
logReporter = opened.$1;
logFilePath = p.relative(config.logFile);
reporters.add(logReporter!);
}
}
reporters.add(switch (config.output.resolve()) {
OutputMode.interactive => InteractiveReporter(logFilePath: logFilePath),
OutputMode.json => JsonReporter(logFilePath: logFilePath),
OutputMode.verbose => PlainReporter(printOutput: true, useColor: stdout.supportsAnsiEscapes, logFilePath: logFilePath),
// `auto` is already resolved to one of the other modes
OutputMode.plain || OutputMode.auto => PlainReporter(printOutput: false, useColor: stdout.supportsAnsiEscapes, logFilePath: logFilePath),
});
PipeRunInfo info = PipeRunInfo(command: command, workflow: config.workflowName, version: "${config.version}+${config.buildVersion}");
PipeRunResult result = await PipeRunner(reporters).run(info, stages);
if (logReporter?.writeError != null) {
Console.logWarning("Parts of this run could not be written to the log file -> ${logReporter!.writeError}");
}
return result;
}