runGates function

Future<GateOutcome> runGates({
  1. required String projectRoot,
  2. ProcessRunner processRunner = const ProcessRunner(),
  3. Map<String, String>? environment,
  4. List<CommandRecord> commandsToRun = validationCommands,
})

Implementation

Future<GateOutcome> runGates({
  required String projectRoot,
  ProcessRunner processRunner = const ProcessRunner(),
  Map<String, String>? environment,
  List<CommandRecord> commandsToRun = validationCommands,
}) async {
  final commands = <CommandRecord>[];
  final exitCodes = <int>[];
  final outputs = <String>[];

  for (final command in commandsToRun) {
    commands.add(command);
    final result = await processRunner.run(
      command.executable,
      command.argumentList,
      workingDirectory: projectRoot,
      environment: environment,
    );
    exitCodes.add(result.exitCode);
    outputs.add(_output(result));
    if (result.exitCode != 0) break;
  }

  return GateOutcome(
    commands: commands,
    exitCodes: exitCodes,
    outputs: outputs,
    passed:
        commands.length == commandsToRun.length &&
        exitCodes.every((code) => code == 0),
  );
}