@@ -173,6 +173,32 @@ type CompilationStats struct {
173173 FailedWorkflows []string // Names of workflows that failed compilation
174174}
175175
176+ // validateCompileConfig validates the configuration flags before compilation
177+ // This is extracted for faster testing without full compilation
178+ func validateCompileConfig (config CompileConfig ) error {
179+ // Validate dependabot flag usage
180+ if config .Dependabot {
181+ if len (config .MarkdownFiles ) > 0 {
182+ return fmt .Errorf ("--dependabot flag cannot be used with specific workflow files" )
183+ }
184+ if config .WorkflowDir != "" && config .WorkflowDir != ".github/workflows" {
185+ return fmt .Errorf ("--dependabot flag cannot be used with custom --workflows-dir" )
186+ }
187+ }
188+
189+ // Validate purge flag usage
190+ if config .Purge && len (config .MarkdownFiles ) > 0 {
191+ return fmt .Errorf ("--purge flag can only be used when compiling all markdown files (no specific files specified)" )
192+ }
193+
194+ // Validate workflow directory path
195+ if config .WorkflowDir != "" && filepath .IsAbs (config .WorkflowDir ) {
196+ return fmt .Errorf ("workflows-dir must be a relative path, got: %s" , config .WorkflowDir )
197+ }
198+
199+ return nil
200+ }
201+
176202func CompileWorkflows (config CompileConfig ) ([]* workflow.WorkflowData , error ) {
177203 markdownFiles := config .MarkdownFiles
178204 verbose := config .Verbose
@@ -196,30 +222,16 @@ func CompileWorkflows(config CompileConfig) ([]*workflow.WorkflowData, error) {
196222 // Track compilation statistics
197223 stats := & CompilationStats {}
198224
199- // Validate dependabot flag usage
200- if dependabot {
201- if len (markdownFiles ) > 0 {
202- return nil , fmt .Errorf ("--dependabot flag cannot be used with specific workflow files" )
203- }
204- if workflowDir != "" && workflowDir != ".github/workflows" {
205- return nil , fmt .Errorf ("--dependabot flag cannot be used with custom --workflows-dir" )
206- }
207- }
208-
209- // Validate purge flag usage
210- if purge && len (markdownFiles ) > 0 {
211- return nil , fmt .Errorf ("--purge flag can only be used when compiling all markdown files (no specific files specified)" )
225+ // Validate configuration
226+ if err := validateCompileConfig (config ); err != nil {
227+ return nil , err
212228 }
213229
214230 // Validate and set default for workflow directory
215231 if workflowDir == "" {
216232 workflowDir = ".github/workflows"
217233 compileLog .Printf ("Using default workflow directory: %s" , workflowDir )
218234 } else {
219- // Ensure the path is relative
220- if filepath .IsAbs (workflowDir ) {
221- return nil , fmt .Errorf ("workflows-dir must be a relative path, got: %s" , workflowDir )
222- }
223235 // Clean the path to avoid issues with ".." or other problematic elements
224236 workflowDir = filepath .Clean (workflowDir )
225237 compileLog .Printf ("Using custom workflow directory: %s" , workflowDir )
0 commit comments