2020-06-26 08:23:54 +00:00
|
|
|
package workflows
|
|
|
|
|
|
|
|
import (
|
2020-06-26 12:37:55 +00:00
|
|
|
"errors"
|
2020-06-26 08:23:54 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Parse a yaml workflow file
|
|
|
|
func Parse(file string) (*Workflow, error) {
|
|
|
|
workflow := &Workflow{}
|
|
|
|
|
|
|
|
f, err := os.Open(file)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
err = yaml.NewDecoder(f).Decode(workflow)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-06-26 12:37:55 +00:00
|
|
|
if workflow.Logic == "" {
|
2020-08-25 21:24:31 +00:00
|
|
|
return nil, errors.New("no logic provided")
|
2020-06-26 12:37:55 +00:00
|
|
|
}
|
|
|
|
|
2020-07-26 18:14:05 +00:00
|
|
|
workflow.path = file
|
|
|
|
|
2020-06-26 08:23:54 +00:00
|
|
|
return workflow, nil
|
|
|
|
}
|