diff --git a/internal/exec/vendor_component_utils.go b/internal/exec/vendor_component_utils.go index 77b599390..ac31f3d9d 100644 --- a/internal/exec/vendor_component_utils.go +++ b/internal/exec/vendor_component_utils.go @@ -22,6 +22,19 @@ import ( cp "github.com/otiai10/copy" ) +// findComponentConfigFile identifies the component vendoring config file (`component.yaml` or `component.yml`) +func findComponentConfigFile(basePath, fileName string) (string, error) { + componentConfigExtensions := []string{"yaml", "yml"} + + for _, ext := range componentConfigExtensions { + configFilePath := path.Join(basePath, fmt.Sprintf("%s.%s", fileName, ext)) + if u.FileExists(configFilePath) { + return configFilePath, nil + } + } + return "", fmt.Errorf("component vendoring config file does not exist in the '%s' folder", basePath) +} + // ReadAndProcessComponentVendorConfigFile reads and processes the component vendoring config file `component.yaml` func ReadAndProcessComponentVendorConfigFile( cliConfig schema.CliConfiguration, @@ -50,12 +63,9 @@ func ReadAndProcessComponentVendorConfigFile( return componentConfig, "", fmt.Errorf("folder '%s' does not exist", componentPath) } - componentConfigFile := path.Join(componentPath, cfg.ComponentVendorConfigFileName) - if !u.FileExists(componentConfigFile) { - return componentConfig, "", fmt.Errorf("component vendoring config file '%s' does not exist in the '%s' folder", - cfg.ComponentVendorConfigFileName, - componentPath, - ) + componentConfigFile, err := findComponentConfigFile(componentPath, strings.TrimSuffix(cfg.ComponentVendorConfigFileName, ".yaml")) + if err != nil { + return componentConfig, "", err } componentConfigFileContent, err := os.ReadFile(componentConfigFile) @@ -92,7 +102,6 @@ func ExecuteComponentVendorInternal( componentPath string, dryRun bool, ) error { - var tempDir string var err error var t *template.Template @@ -180,7 +189,7 @@ func ExecuteComponentVendorInternal( }, } - var tempDir2 = tempDir + tempDir2 := tempDir if sourceIsLocalFile { tempDir2 = path.Join(tempDir, filepath.Base(uri)) } @@ -287,7 +296,7 @@ func ExecuteComponentVendorInternal( }, } - var componentPath2 = componentPath + componentPath2 := componentPath if sourceIsLocalFile { if filepath.Ext(componentPath) == "" { componentPath2 = path.Join(componentPath, filepath.Base(uri))