courgette/internal/commands/execute_workflow.go

52 lines
951 B
Go
Raw Normal View History

package commands
import (
"errors"
"log"
runner "runner/internal/runner"
workflow "runner/internal/workflow"
)
func ExecuteWorkflow(configurationPath string, workflowFile string) error {
configuration, err := NewConfigFromFile(configurationPath)
if err != nil {
return err
}
driver, err := runner.NewDriver(configuration.Containers.Driver)
if err != nil {
return err
}
runnerInstance := runner.NewRunner(
driver,
configuration.Runner.Labels,
)
workflow, err := workflow.FromYamlFile(workflowFile)
if err != nil {
log.Fatalf("%#v", err)
}
validationErrors := workflow.Validate()
if len(validationErrors) > 0 {
for _, err := range validationErrors {
log.Printf("Validation error:: %#v", err)
}
return errors.New("Jobs encountered errors.")
}
taskResult := runnerInstance.Execute(*workflow)
for _, job := range taskResult.Context.Jobs {
log.Printf("Job %s: %s", job.Id, job.Status)
}
return nil
}