2024-08-01 22:43:18 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2024-08-03 17:10:01 +00:00
|
|
|
logger "courgette/internal/logging"
|
2024-08-02 23:49:56 +00:00
|
|
|
workflow "courgette/internal/workflow"
|
2024-08-01 22:43:18 +00:00
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2024-08-02 21:32:41 +00:00
|
|
|
func ValidateWorkflow(configuration Configuration, workflowPath string) error {
|
2024-08-03 17:10:01 +00:00
|
|
|
logger.Info("Validating workflow at \"%s\".", workflowPath)
|
|
|
|
|
2024-08-01 22:43:18 +00:00
|
|
|
workflow, err := workflow.FromYamlFile(workflowPath)
|
|
|
|
|
|
|
|
if err != nil {
|
2024-08-03 17:10:01 +00:00
|
|
|
logger.Error(logger.Red("Failed to read and parse workflow from \"%s\"."), workflowPath)
|
|
|
|
return err
|
2024-08-01 22:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
validationErrors := workflow.Validate()
|
|
|
|
|
|
|
|
if len(validationErrors) > 0 {
|
|
|
|
for _, err := range validationErrors {
|
2024-08-03 17:10:01 +00:00
|
|
|
logger.Error(logger.Red("Validation error: %s"), err)
|
2024-08-01 22:43:18 +00:00
|
|
|
}
|
|
|
|
|
2024-08-03 17:10:01 +00:00
|
|
|
return errors.New("Workflow validation failed.")
|
2024-08-01 22:43:18 +00:00
|
|
|
}
|
|
|
|
|
2024-08-03 17:10:01 +00:00
|
|
|
logger.Info(logger.Green(logger.Bold("✅ Workflow \"%s\" is valid!")), workflowPath)
|
|
|
|
|
2024-08-01 22:43:18 +00:00
|
|
|
return nil
|
|
|
|
}
|