NewValidateCommand creates the validate command
(validateEngine func(string) error)
| 10 | |
| 11 | // NewValidateCommand creates the validate command |
| 12 | func NewValidateCommand(validateEngine func(string) error) *cobra.Command { |
| 13 | cmd := &cobra.Command{ |
| 14 | Use: "validate [workflow]...", |
| 15 | Short: "Validate agentic workflows without generating lock files", |
| 16 | Long: `Validate one or more agentic workflows by compiling and running all linters without |
| 17 | generating lock files. This is equivalent to: |
| 18 | gh aw compile --validate --no-emit --zizmor --actionlint --poutine |
| 19 | |
| 20 | If no workflows are specified, all Markdown files in .github/workflows will be validated. |
| 21 | |
| 22 | ` + WorkflowIDExplanation, |
| 23 | Example: ` ` + string(constants.CLIExtensionPrefix) + ` validate # Validate all workflows |
| 24 | ` + string(constants.CLIExtensionPrefix) + ` validate ci-doctor # Validate a specific workflow |
| 25 | ` + string(constants.CLIExtensionPrefix) + ` validate ci-doctor daily # Validate multiple workflows |
| 26 | ` + string(constants.CLIExtensionPrefix) + ` validate workflow.md # Validate by file path |
| 27 | ` + string(constants.CLIExtensionPrefix) + ` validate --dir custom/workflows # Validate from custom directory |
| 28 | ` + string(constants.CLIExtensionPrefix) + ` validate --json # Output results in JSON format |
| 29 | ` + string(constants.CLIExtensionPrefix) + ` validate --strict # Enforce strict mode validation |
| 30 | ` + string(constants.CLIExtensionPrefix) + ` validate --fail-fast # Stop at the first error`, |
| 31 | RunE: func(cmd *cobra.Command, args []string) error { |
| 32 | engineOverride, _ := cmd.Flags().GetString("engine") |
| 33 | dir, _ := cmd.Flags().GetString("dir") |
| 34 | strict, _ := cmd.Flags().GetBool("strict") |
| 35 | jsonOutput, _ := cmd.Flags().GetBool("json") |
| 36 | failFast, _ := cmd.Flags().GetBool("fail-fast") |
| 37 | stats, _ := cmd.Flags().GetBool("stats") |
| 38 | allowActionRefs, _ := cmd.Flags().GetBool("allow-action-refs") |
| 39 | noCheckUpdate, _ := cmd.Flags().GetBool("no-check-update") |
| 40 | validateImages, _ := cmd.Flags().GetBool("validate-images") |
| 41 | verbose, _ := cmd.Flags().GetBool("verbose") |
| 42 | |
| 43 | if err := validateEngine(engineOverride); err != nil { |
| 44 | return err |
| 45 | } |
| 46 | |
| 47 | // Check for updates (non-blocking, runs once per day) |
| 48 | CheckForUpdatesAsync(cmd.Context(), noCheckUpdate, verbose) |
| 49 | |
| 50 | validateLog.Printf("Running validate command: workflows=%v, dir=%s", args, dir) |
| 51 | |
| 52 | config := CompileConfig{ |
| 53 | MarkdownFiles: args, |
| 54 | Verbose: verbose, |
| 55 | EngineOverride: engineOverride, |
| 56 | Validate: true, |
| 57 | NoEmit: true, |
| 58 | Zizmor: true, |
| 59 | Actionlint: true, |
| 60 | Poutine: true, |
| 61 | WorkflowDir: dir, |
| 62 | Strict: strict, |
| 63 | JSONOutput: jsonOutput, |
| 64 | FailFast: failFast, |
| 65 | Stats: stats, |
| 66 | AllowActionRefs: allowActionRefs, |
| 67 | ValidateImages: validateImages, |
| 68 | } |
| 69 | if _, err := CompileWorkflows(cmd.Context(), config); err != nil { |