courgette/internal/commands/validate.go

32 lines
773 B
Go

package commands
import (
logger "courgette/internal/logging"
workflow "courgette/internal/workflow"
"errors"
)
func ValidateWorkflow(configuration Configuration, workflowPath string) error {
logger.Info("Validating workflow at \"%s\".", workflowPath)
workflow, err := workflow.FromYamlFile(workflowPath)
if err != nil {
logger.Error(logger.Red("Failed to read and parse workflow from \"%s\"."), workflowPath)
return err
}
validationErrors := workflow.Validate()
if len(validationErrors) > 0 {
for _, err := range validationErrors {
logger.Error(logger.Red("Validation error: %s"), err)
}
return errors.New("Workflow validation failed.")
}
logger.Info(logger.Green(logger.Bold("✅ Workflow \"%s\" is valid!")), workflowPath)
return nil
}