LoadWorkflow parses a workflow definition from a YAML or JSON file (JSON is valid YAML). It does not validate the contents – call Validate before running.
(path string)
| 45 | // LoadWorkflow parses a workflow definition from a YAML or JSON file (JSON is |
| 46 | // valid YAML). It does not validate the contents – call Validate before running. |
| 47 | func LoadWorkflow(path string) (wf *Workflow, err error) { |
| 48 | absPath, err := util.GetAbsolutePath(path) |
| 49 | if err != nil { |
| 50 | return nil, fmt.Errorf("invalid workflow path: %w", err) |
| 51 | } |
| 52 | |
| 53 | data, err := os.ReadFile(absPath) |
| 54 | if err != nil { |
| 55 | return nil, fmt.Errorf("error reading workflow file: %w", err) |
| 56 | } |
| 57 | |
| 58 | wf = &Workflow{} |
| 59 | if err = yaml.Unmarshal(data, wf); err != nil { |
| 60 | return nil, fmt.Errorf("error parsing workflow file: %w", err) |
| 61 | } |
| 62 | return |
| 63 | } |
| 64 | |
| 65 | // Validate performs all pre-flight checks on a workflow: |
| 66 | // - at least one step is defined |