From abdb92c0f2c84b3206a4f2ec3175827cf1feff30 Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Wed, 8 Aug 2018 10:58:26 -0400 Subject: [PATCH 1/2] Allow major.minor versions --- config.go | 5 ++++- config_test.go | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index 80cc316c..f87fde32 100644 --- a/config.go +++ b/config.go @@ -357,7 +357,7 @@ func (config *TGFConfig) GetImageName() string { } // https://regex101.com/r/ZKt4OP/2/ -var reVersion = regexp.MustCompile(`^(?P.*?)(:((?P\d+\.\d+\.\d+)((?P[\.-])(?P.+))?|(?P.+))?)?$`) +var reVersion = regexp.MustCompile(`^(?P.*?)(:((?P\d+\.\d+(?:\.\d+){0,1})((?P[\.-])(?P.+))?|(?P.+)))?$`) func (config *TGFConfig) apply(key, value string) { matches := reVersion.FindStringSubmatch(value) @@ -414,6 +414,9 @@ func findConfigFiles(folder string) (result []string) { // CheckVersionRange compare a version with a range of values // Check https://github.com/blang/semver/blob/master/README.md for more information func CheckVersionRange(version, compare string) (bool, error) { + if strings.Count(version, ".") == 1 { + version = version + ".9999" // Patch is irrelevant if major and minor are OK + } v, err := semver.Make(version) if err != nil { return false, err diff --git a/config_test.go b/config_test.go index dc8783a4..dc02dce1 100644 --- a/config_test.go +++ b/config_test.go @@ -15,6 +15,9 @@ func TestCheckVersionRange(t *testing.T) { }{ {"Invalid version", args{"x", "y"}, false, true}, {"Valid", args{"1.20.0", ">=1.19.x"}, true, false}, + {"Valid major minor", args{"1.19", ">=1.19.5"}, true, false}, + {"Valid major minor 2", args{"1.19", ">=1.19.x"}, true, false}, + {"Invalid major minor", args{"1.18", ">=1.19.x"}, false, false}, {"Out of range", args{"1.15.9-Beta.1", ">=1.19.x"}, false, false}, {"Same", args{"1.22.1", "=1.22.1"}, true, false}, {"Not same", args{"1.22.1", "=1.22.2"}, false, false}, From 7f718b4cf5ab4a9fd38cbc628ee456cf7e45bdac Mon Sep 17 00:00:00 2001 From: Julien Duchesne Date: Wed, 8 Aug 2018 11:00:40 -0400 Subject: [PATCH 2/2] Update regex link --- config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.go b/config.go index f87fde32..2890668e 100644 --- a/config.go +++ b/config.go @@ -356,7 +356,7 @@ func (config *TGFConfig) GetImageName() string { return config.Image } -// https://regex101.com/r/ZKt4OP/2/ +// https://regex101.com/r/ZKt4OP/3/ var reVersion = regexp.MustCompile(`^(?P.*?)(:((?P\d+\.\d+(?:\.\d+){0,1})((?P[\.-])(?P.+))?|(?P.+)))?$`) func (config *TGFConfig) apply(key, value string) {