2024-08-01 22:43:18 +00:00
|
|
|
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.")
|
|
|
|
}
|
|
|
|
|
2024-08-02 02:48:54 +00:00
|
|
|
taskResult := runnerInstance.Execute(*workflow)
|
2024-08-01 22:43:18 +00:00
|
|
|
|
2024-08-02 02:48:54 +00:00
|
|
|
for _, job := range taskResult.Context.Jobs {
|
|
|
|
log.Printf("Job %s: %s", job.Id, job.Status)
|
2024-08-01 22:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|