fromWorkflow static method

(({HookCommands build, HookCommands publish})?, List<BPConfigValidationError>) fromWorkflow(
  1. YamlMap workflow
)

Reads the pre_platform_run and post_platform_run of a workflow, for both the build and the publish commands

Implementation

static (({HookCommands build, HookCommands publish})?, List<BPConfigValidationError>) fromWorkflow(yaml.YamlMap workflow) {
  List<String> errors = [];
  Map<String, String?> pre = {};
  Map<String, (String?, String?)> post = {};

  if (workflow.containsKey("pre_platform_run")) {
    Map? preRun = _commandsObject(workflow["pre_platform_run"], "pre_platform_run", errors);
    for (String command in commands) {
      if (preRun != null && preRun.containsKey(command)) {
        pre[command] = _command(preRun[command], "pre_platform_run.$command", errors);
      }
    }
  }

  if (workflow.containsKey("post_platform_run")) {
    Map? postRun = _commandsObject(workflow["post_platform_run"], "post_platform_run", errors);
    for (String command in commands) {
      if (postRun != null && postRun.containsKey(command)) {
        post[command] = _post(postRun[command], "post_platform_run.$command", errors);
      }
    }
  }

  if (errors.isNotEmpty) return (null, _toErrors(errors));

  HookCommands hooksOf(String command) {
    return HookCommands(pre: pre[command], onSuccess: post[command]?.$1, finallyCommand: post[command]?.$2);
  }

  return ((build: hooksOf("build"), publish: hooksOf("publish")), []);
}