diff --git a/testing/hooks/validation/exported_struct_test.go b/testing/hooks/validation/exported_struct_test.go index 1df2d684fb..5332ec4f7e 100644 --- a/testing/hooks/validation/exported_struct_test.go +++ b/testing/hooks/validation/exported_struct_test.go @@ -32,6 +32,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "gopkg.in/yaml.v2" ) // Check that structures which are used by FilterFunc don't have unexported fields @@ -62,13 +63,41 @@ type structCheckResult struct { Line int } +type edition struct { + Name string `yaml:"name,omitempty"` + ModulesDir string `yaml:"modulesDir,omitempty"` +} + +type editions struct { + Editions []edition `yaml:"editions,omitempty"` +} + +func getPossiblePathToModules() []string { + content, err := os.ReadFile("/deckhouse/editions.yaml") + if err != nil { + panic(fmt.Sprintf("cannot read editions file: %v", err)) + } + + e := editions{} + err = yaml.Unmarshal(content, &e) + if err != nil { + panic(fmt.Errorf("cannot unmarshal editions file: %v", err)) + } + + modulesDir := make([]string, 0) + for i, ed := range e.Editions { + if ed.Name == "" { + panic(fmt.Sprintf("name for %d index is empty", i)) + } + modulesDir = append(modulesDir, fmt.Sprintf("/deckhouse/%s/*/hooks", ed.ModulesDir)) + } + + return modulesDir +} + func collectGoHooks() []string { var hookDirs []string - for _, possibleDir := range []string{ - "/deckhouse/modules/*/hooks", - "/deckhouse/ee/modules/*/hooks", - "/deckhouse/ee/fe/modules/*/hooks", - } { + for _, possibleDir := range getPossiblePathToModules() { result, err := filepath.Glob(possibleDir) if err != nil { diff --git a/testing/matrix/linter/rules/modules/modules.go b/testing/matrix/linter/rules/modules/modules.go index 91424415d5..b18e7b68b5 100644 --- a/testing/matrix/linter/rules/modules/modules.go +++ b/testing/matrix/linter/rules/modules/modules.go @@ -143,15 +143,43 @@ func helmignoreModuleRule(name, path string) errors.LintRuleError { return errors.EmptyRuleError } +type edition struct { + Name string `yaml:"name,omitempty"` + ModulesDir string `yaml:"modulesDir,omitempty"` +} + +type editions struct { + Editions []edition `yaml:"editions,omitempty"` +} + +func getPossiblePathToModules() []string { + content, err := os.ReadFile("/deckhouse/editions.yaml") + if err != nil { + panic(fmt.Sprintf("cannot read editions file: %v", err)) + } + + e := editions{} + err = yaml.Unmarshal(content, &e) + if err != nil { + panic(fmt.Errorf("cannot unmarshal editions file: %v", err)) + } + + modulesDir := make([]string, 0) + for i, ed := range e.Editions { + if ed.Name == "" { + panic(fmt.Sprintf("name for %d index is empty", i)) + } + modulesDir = append(modulesDir, fmt.Sprintf("/deckhouse/%s", ed.ModulesDir)) + } + + return modulesDir +} + func GetDeckhouseModulesWithValuesMatrixTests(focusNames set.Set) (modules []utils.Module, err error) { var possibleModulesPaths []string modulesDir, ok := os.LookupEnv("MODULES_DIR") if !ok { - possibleModulesPaths = []string{ - "/deckhouse/modules", - "/deckhouse/ee/modules", - "/deckhouse/ee/fe/modules", - } + possibleModulesPaths = getPossiblePathToModules() } else { possibleModulesPaths = strings.Split(modulesDir, ":") } diff --git a/testing/openapi_cases/library.go b/testing/openapi_cases/library.go index cf3f6db917..9d1c439177 100644 --- a/testing/openapi_cases/library.go +++ b/testing/openapi_cases/library.go @@ -73,17 +73,45 @@ func (t *TestCases) HaveHelmValuesCases() bool { return len(t.Positive.HelmValues) > 0 || len(t.Negative.HelmValues) > 0 } +type edition struct { + Name string `yaml:"name,omitempty"` + ModulesDir string `yaml:"modulesDir,omitempty"` +} + +type editions struct { + Editions []edition `yaml:"editions,omitempty"` +} + +func getPossiblePathToModules() []string { + content, err := os.ReadFile("/deckhouse/editions.yaml") + if err != nil { + panic(fmt.Sprintf("cannot read editions file: %v", err)) + } + + e := editions{} + err = yaml.Unmarshal(content, &e) + if err != nil { + panic(fmt.Errorf("cannot unmarshal editions file: %v", err)) + } + + modulesDir := make([]string, 0) + for i, ed := range e.Editions { + if ed.Name == "" { + panic(fmt.Sprintf("name for %d index is empty", i)) + } + modulesDir = append(modulesDir, fmt.Sprintf("/deckhouse/%s/*/openapi", ed.ModulesDir)) + } + + return modulesDir +} + func GetAllOpenAPIDirs() ([]string, error) { var ( dirs []string openAPIDirs []string ) - for _, possibleDir := range []string{ - "/deckhouse/modules/*/openapi", - "/deckhouse/ee/modules/*/openapi", - "/deckhouse/ee/fe/modules/*/openapi", - } { + for _, possibleDir := range getPossiblePathToModules() { globDirs, err := filepath.Glob(possibleDir) if err != nil { return nil, err diff --git a/werf.yaml b/werf.yaml index fc3a896fe5..8d497fd59d 100644 --- a/werf.yaml +++ b/werf.yaml @@ -413,6 +413,7 @@ git: - testing - go.mod - go.sum + - editions.yaml excludePaths: {{ .Files.Get (printf "tools/build_includes/modules-excluded-%s.yaml" .Env) | nindent 2}} - docs