courgette/internal/commands/validate.go

33 lines
773 B
Go
Raw Normal View History

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"
"errors"
)
func ValidateWorkflow(configuration Configuration, workflowPath string) error {
2024-08-03 17:10:01 +00:00
logger.Info("Validating workflow at \"%s\".", workflowPath)
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
}
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-03 17:10:01 +00:00
return errors.New("Workflow validation failed.")
}
2024-08-03 17:10:01 +00:00
logger.Info(logger.Green(logger.Bold("✅ Workflow \"%s\" is valid!")), workflowPath)
return nil
}