Skip to content

Commit

Permalink
Merge pull request #23 from coveo/major-minor-versions
Browse files Browse the repository at this point in the history
Allow major.minor versions
  • Loading branch information
julienduchesne authored Aug 8, 2018
2 parents aabb54a + 7f718b4 commit b93e3f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ func (config *TGFConfig) GetImageName() string {
return config.Image
}

// https://regex101.com/r/ZKt4OP/2/
var reVersion = regexp.MustCompile(`^(?P<image>.*?)(:((?P<version>\d+\.\d+\.\d+)((?P<sep>[\.-])(?P<spec>.+))?|(?P<fix>.+))?)?$`)
// https://regex101.com/r/ZKt4OP/3/
var reVersion = regexp.MustCompile(`^(?P<image>.*?)(:((?P<version>\d+\.\d+(?:\.\d+){0,1})((?P<sep>[\.-])(?P<spec>.+))?|(?P<fix>.+)))?$`)

func (config *TGFConfig) apply(key, value string) {
matches := reVersion.FindStringSubmatch(value)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit b93e3f1

Please sign in to comment.