Files
gh-action-readme/internal/dependencies/parser.go
Ismo Vuorinen f94967713a refactor: major codebase improvements and test framework overhaul
This commit represents a comprehensive refactoring of the codebase focused on
improving code quality, testability, and maintainability.

Key improvements:
- Implement dependency injection and interface-based architecture
- Add comprehensive test framework with fixtures and test suites
- Fix all linting issues (errcheck, gosec, staticcheck, goconst, etc.)
- Achieve full EditorConfig compliance across all files
- Replace hardcoded test data with proper fixture files
- Add configuration loader with hierarchical config support
- Improve error handling with contextual information
- Add progress indicators for better user feedback
- Enhance Makefile with help system and improved editorconfig commands
- Consolidate constants and remove deprecated code
- Strengthen validation logic for GitHub Actions
- Add focused consumer interfaces for better separation of concerns

Testing improvements:
- Add comprehensive integration tests
- Implement test executor pattern for better test organization
- Create extensive YAML fixture library for testing
- Fix all failing tests and improve test coverage
- Add validation test fixtures to avoid embedded YAML in Go files

Build and tooling:
- Update Makefile to show help by default
- Fix editorconfig commands to use eclint properly
- Add comprehensive help documentation to all make targets
- Improve file selection patterns to avoid glob errors

This refactoring maintains backward compatibility while significantly
improving the internal architecture and developer experience.
2025-08-05 23:20:58 +03:00

52 lines
1.4 KiB
Go

package dependencies
import (
"fmt"
"os"
"gopkg.in/yaml.v3"
)
// parseCompositeActionFromFile reads and parses a composite action file.
func (a *Analyzer) parseCompositeActionFromFile(actionPath string) (*ActionWithComposite, error) {
// Read the file
data, err := os.ReadFile(actionPath) // #nosec G304 -- action path from function parameter
if err != nil {
return nil, fmt.Errorf("failed to read action file %s: %w", actionPath, err)
}
// Parse YAML
var action ActionWithComposite
if err := yaml.Unmarshal(data, &action); err != nil {
return nil, fmt.Errorf("failed to parse YAML: %w", err)
}
return &action, nil
}
// parseCompositeAction parses an action.yml file with composite action support.
func (a *Analyzer) parseCompositeAction(actionPath string) (*ActionWithComposite, error) {
// Use the real file parser
action, err := a.parseCompositeActionFromFile(actionPath)
if err != nil {
return nil, err
}
// If this is not a composite action, return empty steps
if action.Runs.Using != compositeUsing {
action.Runs.Steps = []CompositeStep{}
}
return action, nil
}
// IsCompositeAction checks if an action file defines a composite action.
func IsCompositeAction(actionPath string) (bool, error) {
action, err := (&Analyzer{}).parseCompositeActionFromFile(actionPath)
if err != nil {
return false, err
}
return action.Runs.Using == compositeUsing, nil
}