50 lines
975 B
Go
50 lines
975 B
Go
package commands
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
runner "runner/internal/runner"
|
|
workflow "runner/internal/workflow"
|
|
)
|
|
|
|
func ExecuteWorkflow(configuration Configuration, workflowFile string) error {
|
|
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)
|
|
|
|
if !taskResult.HasError() {
|
|
return nil
|
|
}
|
|
|
|
for _, job := range taskResult.Context.Jobs {
|
|
log.Printf("Job %s: %s", job.Id, job.Status)
|
|
}
|
|
|
|
return fmt.Errorf("Task %s failed with at least 1 error.", taskResult.Id)
|
|
}
|