From fdc500d6aa73c3490320b341fe519d1cd7470e80 Mon Sep 17 00:00:00 2001 From: thepetk Date: Thu, 6 Jul 2023 17:17:06 +0100 Subject: [PATCH 1/6] Remove dependabot Signed-off-by: thepetk@gmail.com Signed-off-by: thepetk --- .github/dependabot.yml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index b444581e..00000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,11 +0,0 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - -version: 2 -updates: - - package-ecosystem: "gomod" # See documentation for possible values - directory: "/" # Location of package manifests - schedule: - interval: "daily" From e243bd9a9fae9c12556460bf30d9c8e21da07082 Mon Sep 17 00:00:00 2001 From: thepetk Date: Fri, 7 Jul 2023 16:36:55 +0100 Subject: [PATCH 2/6] Add versions to alizer devfile response Signed-off-by: thepetk --- pkg/apis/model/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/model/model.go b/pkg/apis/model/model.go index 94740290..fee7b69a 100644 --- a/pkg/apis/model/model.go +++ b/pkg/apis/model/model.go @@ -45,7 +45,6 @@ type Component struct { type Version struct { SchemaVersion string Default bool - Version string } type DevFileType struct { @@ -53,6 +52,7 @@ type DevFileType struct { Language string ProjectType string Tags []string + Versions []Version } type DevfileFilter struct { From 8837758e0a0c2cab9a518f7bd63e4ae1ab0349b8 Mon Sep 17 00:00:00 2001 From: thepetk Date: Fri, 7 Jul 2023 16:49:51 +0100 Subject: [PATCH 3/6] Update readme.md Signed-off-by: thepetk --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6e6ceb2f..74a48855 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,8 @@ $ go build alizer.go ```sh --log {debug|info|warning} sets the logging level of the CLI. The arg accepts only 3 values [`debug`, `info`, `warning`]. The default value is `warning` and the logging level is `ErrorLevel`. --registry strings registry where to download the devfiles. Default value: https://registry.devfile.io - --min-version strings the minimum SchemaVersion of the matched devfile(s). The minimum accepted value is `2.0.0`, otherwise an error is returned. - --max-version strings the maximum SchemaVersion of the matched devfile(s). The minimum accepted value is `2.0.0`, otherwise an error is returned. + --min-schema-version strings the minimum SchemaVersion of the matched devfile(s). The minimum accepted value is `2.0.0`, otherwise an error is returned. + --max-schema-version strings the maximum SchemaVersion of the matched devfile(s). The minimum accepted value is `2.0.0`, otherwise an error is returned. ``` ### Library Package From d63b8e78deba2729ccf2ce93bc2105c73a6e82eb Mon Sep 17 00:00:00 2001 From: thepetk Date: Fri, 7 Jul 2023 16:50:27 +0100 Subject: [PATCH 4/6] Update naming and devfile models in the proposal Signed-off-by: thepetk --- docs/proposals/support_22x_devfiles.md | 50 +++++++++++++++----------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/docs/proposals/support_22x_devfiles.md b/docs/proposals/support_22x_devfiles.md index 8f5ee53e..7c37351c 100644 --- a/docs/proposals/support_22x_devfiles.md +++ b/docs/proposals/support_22x_devfiles.md @@ -17,10 +17,10 @@ As mentioned above, there is common ground on the two issues. This means that we ## CLI Arguments The `alizer devfile` command should have arguments in order to specify which devfiles are acceptable or not. -### max-version +### max-schema-version If this argument is passed in a alizer devfile command then, alizer should match a devfile with **equal or older version** than the one given. -### min-version +### min-schema-version If this argument is passed in a alizer devfile command then, alizer should match a devfile with **equal or newer version** than the one given. _The results of devfiles have to be sorted from newest to oldest._ @@ -104,10 +104,10 @@ metadata: ... ``` -### Case A - Define only a max-version. -If we choose `max-version = 2.1.0` we should get a list of 2 devfiles from our devfile command: +### Case A - Define only a max-schema-version. +If we choose `max-schema-version = 2.1.0` we should get a list of 2 devfiles from our devfile command: ```bash -$ ./alizer devfile --max-version 2.1.0 +$ ./alizer devfile --max-schema-version 2.1.0 [ { "Name": "devfileB", @@ -128,10 +128,10 @@ $ ./alizer devfile --max-version 2.1.0 ] ``` -### Case B - Define only a min-version. -If we choose `min-version = 2.1.0` we should get a list of 2 devfiles from our devfile command: +### Case B - Define only a min-schema-version. +If we choose `min-schema-version = 2.1.0` we should get a list of 2 devfiles from our devfile command: ```bash -$ ./alizer devfile --min-version 2.1.0 +$ ./alizer devfile --min-schema-version 2.1.0 [ { "Name": "devfileC", @@ -152,10 +152,10 @@ $ ./alizer devfile --min-version 2.1.0 ] ``` -### Case C - Define both min-version and max-version. -If we choose `min-version = 2.1.0` and `max-version = 2.1.2` we should get a list of 1 devfile from our devfile command: +### Case C - Define both min-schema-version and max-schema-version. +If we choose `min-schema-version = 2.1.0` and `max-schema-version = 2.1.2` we should get a list of 1 devfile from our devfile command: ```bash -$ ./alizer devfile --min-version 2.1.0 --max-version 2.1.2 +$ ./alizer devfile --min-schema-version 2.1.0 --max-schema-version 2.1.2 [ { "Name": "devfileB", @@ -168,7 +168,7 @@ $ ./alizer devfile --min-version 2.1.0 --max-version 2.1.2 ] ``` -_An error will be raised if the min-version is greater than the max-version_ +_An error will be raised if the min-schema-version is greater than the max-schema-version_ ## Library In order to facilitate these updates we will have to update our library. The main work will focus inside `devfile_recognizer.go`. There, we will have to implement a new function (`MatchDevfiles`) which will handle cases that we want to filter the devfiles list fetched from a registry. Another addition would be to add a new attribute `SchemaVersion` string in the `model.DevFileType` (`SchemaVersion string`). @@ -181,21 +181,29 @@ _We have to keep the old way of fetching devfiles from library in order to ensur This function will take 3 parameters `(path string, devFileTypes []model.DevFileType, filter map[string]interface{})`. If someone wants to filter the selected devfiles for specific version range the have to write: ```golang import "github.com/devfile/alizer/pkg/apis/recognizer" -filter := map[string]interface{} { - "max-version": "2.1.0", - "min-version": "2.0.0", +import "github.com/devfile/alizer/pkg/apis/model" + +devifileFilter := model.DevfileFilter { + MinSchemaVersion: "2.0.0", + MaxSchemaVersion: "2.2.0", } -devfiles, err := recognizer.MatchDevfiles("myproject", devfiles, filter) +devfiles, err := recognizer.MatchDevfiles("myproject", devfiles, devifileFilter) ``` ### model.DevfileType In order to be able to check and compare the version of each devfile with the given attribute we have to create a dedicated attribute inside this model: ```golang +type Version struct { + SchemaVersion string + Default bool + Version string +} + type DevFileType struct { - Name string - Language string - ProjectType string - Tags []string - SchemaVersion string + Name string + Language string + ProjectType string + Tags []string + Versions []Version } ``` \ No newline at end of file From 22c67a74e4226d77e10573d91de73b70a94b08ae Mon Sep 17 00:00:00 2001 From: thepetk Date: Fri, 7 Jul 2023 16:50:57 +0100 Subject: [PATCH 5/6] Update code naming Signed-off-by: thepetk --- pkg/apis/model/model.go | 5 ++-- pkg/apis/recognizer/devfile_recognizer.go | 30 +++++++++++------------ pkg/cli/devfile/devfile.go | 10 ++++---- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/pkg/apis/model/model.go b/pkg/apis/model/model.go index fee7b69a..21ca1a07 100644 --- a/pkg/apis/model/model.go +++ b/pkg/apis/model/model.go @@ -45,6 +45,7 @@ type Component struct { type Version struct { SchemaVersion string Default bool + Version string } type DevFileType struct { @@ -56,8 +57,8 @@ type DevFileType struct { } type DevfileFilter struct { - MinVersion string - MaxVersion string + MinSchemaVersion string + MaxSchemaVersion string } type ApplicationFileInfo struct { diff --git a/pkg/apis/recognizer/devfile_recognizer.go b/pkg/apis/recognizer/devfile_recognizer.go index 407494b7..cea48449 100644 --- a/pkg/apis/recognizer/devfile_recognizer.go +++ b/pkg/apis/recognizer/devfile_recognizer.go @@ -121,7 +121,7 @@ func SelectDevFilesFromRegistry(path string, url string) ([]model.DevFileType, e alizerLogger := utils.GetOrCreateLogger() alizerLogger.V(0).Info("Starting devfile matching") alizerLogger.V(1).Info(fmt.Sprintf("Downloading devfiles from registry %s", url)) - devFileTypesFromRegistry, err := downloadDevFileTypesFromRegistry(url, model.DevfileFilter{MinVersion: "", MaxVersion: ""}) + devFileTypesFromRegistry, err := downloadDevFileTypesFromRegistry(url, model.DevfileFilter{MinSchemaVersion: "", MaxSchemaVersion: ""}) if err != nil { return []model.DevFileType{}, err } @@ -145,7 +145,7 @@ func selectDevfiles(path string, devFileTypesFromRegistry []model.DevFileType) ( } func SelectDevFileFromRegistry(path string, url string) (model.DevFileType, error) { - devFileTypes, err := downloadDevFileTypesFromRegistry(url, model.DevfileFilter{MinVersion: "", MaxVersion: ""}) + devFileTypes, err := downloadDevFileTypesFromRegistry(url, model.DevfileFilter{MinSchemaVersion: "", MaxSchemaVersion: ""}) if err != nil { return model.DevFileType{}, err } @@ -157,47 +157,47 @@ func SelectDevFileFromRegistry(path string, url string) (model.DevFileType, erro return devFileTypes[index], nil } -func GetUrlWithVersions(url, minVersion, maxVersion string) (string, error) { +func GetUrlWithVersions(url, minSchemaVersion, maxSchemaVersion string) (string, error) { minAllowedVersion, err := version.NewVersion(MinimumAllowedVersion) if err != nil { return "", nil } - if minVersion != "" && maxVersion != "" { - minV, err := version.NewVersion(minVersion) + if minSchemaVersion != "" && maxSchemaVersion != "" { + minV, err := version.NewVersion(minSchemaVersion) if err != nil { return url, nil } - maxV, err := version.NewVersion(maxVersion) + maxV, err := version.NewVersion(maxSchemaVersion) if err != nil { return url, nil } if maxV.LessThan(minV) { - return "", fmt.Errorf("max-version cannot be lower than min-version") + return "", fmt.Errorf("max-schema-version cannot be lower than min-schema-version") } if maxV.LessThan(minAllowedVersion) || minV.LessThan(minAllowedVersion) { return "", fmt.Errorf("min and/or max version are lower than the minimum allowed version (2.0.0)") } - return fmt.Sprintf("%s?minSchemaVersion=%s&maxSchemaVersion=%s", url, minVersion, maxVersion), nil - } else if minVersion != "" { - minV, err := version.NewVersion(minVersion) + return fmt.Sprintf("%s?minSchemaVersion=%s&maxSchemaVersion=%s", url, minSchemaVersion, maxSchemaVersion), nil + } else if minSchemaVersion != "" { + minV, err := version.NewVersion(minSchemaVersion) if err != nil { return "", nil } if minV.LessThan(minAllowedVersion) { return "", fmt.Errorf("min version is lower than the minimum allowed version (2.0.0)") } - return fmt.Sprintf("%s?minSchemaVersion=%s", url, minVersion), nil - } else if maxVersion != "" { - maxV, err := version.NewVersion(maxVersion) + return fmt.Sprintf("%s?minSchemaVersion=%s", url, minSchemaVersion), nil + } else if maxSchemaVersion != "" { + maxV, err := version.NewVersion(maxSchemaVersion) if err != nil { return "", nil } if maxV.LessThan(minAllowedVersion) { return "", fmt.Errorf("max version is lower than the minimum allowed version (2.0.0)") } - return fmt.Sprintf("%s?maxSchemaVersion=%s", url, maxVersion), nil + return fmt.Sprintf("%s?maxSchemaVersion=%s", url, maxSchemaVersion), nil } else { return url, nil } @@ -206,7 +206,7 @@ func GetUrlWithVersions(url, minVersion, maxVersion string) (string, error) { func downloadDevFileTypesFromRegistry(url string, filter model.DevfileFilter) ([]model.DevFileType, error) { url = adaptUrl(url) tmpUrl := appendIndexPath(url) - url, err := GetUrlWithVersions(tmpUrl, filter.MinVersion, filter.MaxVersion) + url, err := GetUrlWithVersions(tmpUrl, filter.MinSchemaVersion, filter.MaxSchemaVersion) if err != nil { return nil, err } diff --git a/pkg/cli/devfile/devfile.go b/pkg/cli/devfile/devfile.go index 235fb204..676f58be 100644 --- a/pkg/cli/devfile/devfile.go +++ b/pkg/cli/devfile/devfile.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" ) -var logLevel, registry, minVersion, maxVersion string +var logLevel, registry, minSchemaVersion, maxSchemaVersion string func NewCmdDevfile() *cobra.Command { devfileCmd := &cobra.Command{ @@ -18,8 +18,8 @@ func NewCmdDevfile() *cobra.Command { Run: doSelectDevfile, } devfileCmd.Flags().StringVar(&logLevel, "log", "", "log level for alizer. Default value: error. Accepted values: [debug, info, warning]") - devfileCmd.Flags().StringVar(&minVersion, "min-version", "", "minimum version of devfile schemaVersion. Minimum allowed version: 2.0.0") - devfileCmd.Flags().StringVar(&maxVersion, "max-version", "", "maximum version of devfile schemaVersion. Minimum allowed version: 2.0.0") + devfileCmd.Flags().StringVar(&minSchemaVersion, "min-schema-version", "", "minimum version of devfile schemaVersion. Minimum allowed version: 2.0.0") + devfileCmd.Flags().StringVar(&maxSchemaVersion, "max-schema-version", "", "maximum version of devfile schemaVersion. Minimum allowed version: 2.0.0") devfileCmd.Flags().StringVarP(®istry, "registry", "r", "", "registry where to download the devfiles. Default value: https://registry.devfile.io") return devfileCmd } @@ -38,8 +38,8 @@ func doSelectDevfile(cmd *cobra.Command, args []string) { return } filter := model.DevfileFilter{ - MinVersion: minVersion, - MaxVersion: maxVersion, + MinSchemaVersion: minSchemaVersion, + MaxSchemaVersion: maxSchemaVersion, } utils.PrintPrettifyOutput(recognizer.MatchDevfiles(args[0], registry, filter)) } From 88309eb32645db25b21bf55806cef9f0080580db Mon Sep 17 00:00:00 2001 From: thepetk Date: Fri, 7 Jul 2023 16:51:07 +0100 Subject: [PATCH 6/6] Update tests after renaming Signed-off-by: thepetk --- test/apis/devfile_recognizer_test.go | 110 +++++++++++++-------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/test/apis/devfile_recognizer_test.go b/test/apis/devfile_recognizer_test.go index 65b65a80..d2430a2e 100644 --- a/test/apis/devfile_recognizer_test.go +++ b/test/apis/devfile_recognizer_test.go @@ -137,93 +137,93 @@ func TestDetectLaravelDevfile(t *testing.T) { func TestGetUrlWithVersions(t *testing.T) { tests := []struct { - name string - minVersion string - maxVersion string - testUrl string - expectedError error - expectedUrl string + name string + minSchemaVersion string + maxSchemaVersion string + testUrl string + expectedError error + expectedUrl string }{ { - name: "Case 1: Url with valid min and max versions", - minVersion: "2.0.0", - maxVersion: "2.2.0", - testUrl: "http://localhost:5000/", - expectedError: nil, + name: "Case 1: Url with valid min and max versions", + minSchemaVersion: "2.0.0", + maxSchemaVersion: "2.2.0", + testUrl: "http://localhost:5000/", + expectedError: nil, }, { - name: "Case 2: Url with valid min version", - minVersion: "2.0.0", - maxVersion: "", - testUrl: "http://localhost:5000", - expectedError: nil, + name: "Case 2: Url with valid min version", + minSchemaVersion: "2.0.0", + maxSchemaVersion: "", + testUrl: "http://localhost:5000", + expectedError: nil, }, { - name: "Case 3: Url with valid max version", - minVersion: "", - maxVersion: "2.2.0", - testUrl: "http://localhost:5000/", - expectedError: nil, + name: "Case 3: Url with valid max version", + minSchemaVersion: "", + maxSchemaVersion: "2.2.0", + testUrl: "http://localhost:5000/", + expectedError: nil, }, { - name: "Case 4: Url with max version lower than min version", - minVersion: "2.2.0", - maxVersion: "2.1.0", - testUrl: "http://localhost:5000/v2index", - expectedError: fmt.Errorf("max-version cannot be lower than min-version"), + name: "Case 4: Url with max version lower than min version", + minSchemaVersion: "2.2.0", + maxSchemaVersion: "2.1.0", + testUrl: "http://localhost:5000/v2index", + expectedError: fmt.Errorf("max-schema-version cannot be lower than min-schema-version"), }, { - name: "Case 5: Url with max version lower than minimum allowed version", - minVersion: "0.1.0", - maxVersion: "1.1.0", - testUrl: "http://localhost:5000/v2index", - expectedError: fmt.Errorf("min and/or max version are lower than the minimum allowed version (2.0.0)"), + name: "Case 5: Url with max version lower than minimum allowed version", + minSchemaVersion: "0.1.0", + maxSchemaVersion: "1.1.0", + testUrl: "http://localhost:5000/v2index", + expectedError: fmt.Errorf("min and/or max version are lower than the minimum allowed version (2.0.0)"), }, { - name: "Case 6: Url with max version lower than minimum allowed version & minVersion", - minVersion: "2.1.0", - maxVersion: "1.1.0", - testUrl: "http://localhost:5000/v2index", - expectedError: fmt.Errorf("max-version cannot be lower than min-version"), + name: "Case 6: Url with max-schema-version lower than minimum allowed version & min-schema-version", + minSchemaVersion: "2.1.0", + maxSchemaVersion: "1.1.0", + testUrl: "http://localhost:5000/v2index", + expectedError: fmt.Errorf("max-schema-version cannot be lower than min-schema-version"), }, { - name: "Case 7: Url with min version lower than minimum allowed version", - minVersion: "1.1.0", - maxVersion: "", - testUrl: "http://localhost:5000/v2index", - expectedError: fmt.Errorf("min version is lower than the minimum allowed version (2.0.0)"), + name: "Case 7: Url with min version lower than minimum allowed version", + minSchemaVersion: "1.1.0", + maxSchemaVersion: "", + testUrl: "http://localhost:5000/v2index", + expectedError: fmt.Errorf("min version is lower than the minimum allowed version (2.0.0)"), }, { - name: "Case 8: Url with max version lower than minimum allowed version", - minVersion: "", - maxVersion: "1.1.0", - testUrl: "http://localhost:5000/v2index", - expectedError: fmt.Errorf("max version is lower than the minimum allowed version (2.0.0)"), + name: "Case 8: Url with max version lower than minimum allowed version", + minSchemaVersion: "", + maxSchemaVersion: "1.1.0", + testUrl: "http://localhost:5000/v2index", + expectedError: fmt.Errorf("max version is lower than the minimum allowed version (2.0.0)"), }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - result, err := recognizer.GetUrlWithVersions(tt.testUrl, tt.minVersion, tt.maxVersion) + result, err := recognizer.GetUrlWithVersions(tt.testUrl, tt.minSchemaVersion, tt.maxSchemaVersion) if err != nil { assert.EqualValues(t, tt.expectedError, err) } else { - assert.EqualValues(t, getExceptedVersionsUrl(tt.testUrl, tt.minVersion, tt.maxVersion, tt.expectedError), result) + assert.EqualValues(t, getExceptedVersionsUrl(tt.testUrl, tt.minSchemaVersion, tt.maxSchemaVersion, tt.expectedError), result) } }) } } -func getExceptedVersionsUrl(url, minVersion, maxVersion string, err error) string { +func getExceptedVersionsUrl(url, minSchemaVersion, maxSchemaVersion string, err error) string { if err != nil { return "" - } else if minVersion != "" && maxVersion != "" { - return fmt.Sprintf("%s?minSchemaVersion=%s&maxSchemaVersion=%s", url, minVersion, maxVersion) - } else if minVersion != "" { - return fmt.Sprintf("%s?minSchemaVersion=%s", url, minVersion) - } else if maxVersion != "" { - return fmt.Sprintf("%s?maxSchemaVersion=%s", url, maxVersion) + } else if minSchemaVersion != "" && maxSchemaVersion != "" { + return fmt.Sprintf("%s?minSchemaVersion=%s&maxSchemaVersion=%s", url, minSchemaVersion, maxSchemaVersion) + } else if minSchemaVersion != "" { + return fmt.Sprintf("%s?minSchemaVersion=%s", url, minSchemaVersion) + } else if maxSchemaVersion != "" { + return fmt.Sprintf("%s?maxSchemaVersion=%s", url, maxSchemaVersion) } else { return url }