Skip to content

[Code Quality] Refactor CompileWorkflowData into smaller, testable functions #14391

@github-actions

Description

@github-actions

Description

The CompileWorkflowData() function in compiler.go is 343 lines long (lines 96-439), making it difficult to test individual validation steps and contributing to high cyclomatic complexity. This violates the maintainability guideline of 50 lines maximum per function.

Current State

  • File: pkg/workflow/compiler.go
  • Function: CompileWorkflowData() (343 lines)
  • Quality Score: 83/100
  • Issue: Function exceeds guideline by ~7x (343 vs 50 line recommendation)
  • Impact: Difficult to test validation phases independently

Why This Matters (Release Mode Priority)

  1. Testing Difficulty: Cannot unit test individual validation steps
  2. Complexity: High cyclomatic complexity increases bug risk
  3. Maintainability: Hard to understand and modify validation logic
  4. Code Smell: Violates Single Responsibility Principle

Suggested Changes

Extract validation phases from CompileWorkflowData() into 3 focused methods:

1. validateWorkflowData() - Lines 131-300

// validateWorkflowData performs comprehensive validation of workflow configuration
// including expressions, features, permissions, and configurations.
func (c *Compiler) validateWorkflowData(data *WorkflowData) error {
    // Expression validation
    // Feature validation  
    // Permission validation
    // Configuration validation
    return nil
}

2. generateAndValidateYAML() - Lines 310-386

// generateAndValidateYAML generates GitHub Actions YAML and validates
// the output size and format.
func (c *Compiler) generateAndValidateYAML(data *WorkflowData) (string, error) {
    // Generate YAML
    // Validate size limits
    // ANSI code sanitization
    return yamlContent, nil
}

3. writeWorkflowOutput() - Lines 388-421

// writeWorkflowOutput writes the compiled workflow to the lock file
// and handles console output formatting.
func (c *Compiler) writeWorkflowOutput(lockFilePath, yamlContent string, data *WorkflowData) error {
    // Write to lock file
    // Generate success message
    // Console output formatting
    return nil
}

Refactored CompileWorkflowData() - ~50 lines

func (c *Compiler) CompileWorkflowData(data *WorkflowData, filePath, outputDir string) error {
    // Validate workflow data
    if err := c.validateWorkflowData(data); err != nil {
        return err
    }
    
    // Generate and validate YAML
    yamlContent, err := c.generateAndValidateYAML(data)
    if err != nil {
        return err
    }
    
    // Write output
    lockFilePath := determineLockFilePath(filePath, outputDir)
    return c.writeWorkflowOutput(lockFilePath, yamlContent, data)
}

Files Affected

  • Modified: pkg/workflow/compiler.go (extract functions, reduce CompileWorkflowData from 343→~50 lines)
  • Modified: pkg/workflow/compiler_test.go (add tests for new functions)

Success Criteria

  • CompileWorkflowData() reduced to ~50 lines (orchestration only)
  • Three new methods created with clear responsibilities
  • Each method independently testable
  • All existing tests pass (make test-unit)
  • New tests added for extracted methods
  • Quality score maintained or improved
  • No functional changes (refactor only)

Estimated Effort

2-3 hours - Function extraction and test updates

Priority

High - Improves testability and reduces complexity, directly supporting release stability.

Source

Extracted from Daily Compiler Code Quality Report - 2026-02-07 #14370

References:

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 8, 2026, 5:06 PM UTC

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions