Skip to content

Commit

Permalink
Merge pull request #53 from coveo/refresh-partial-versions
Browse files Browse the repository at this point in the history
Always refresh partial versions
  • Loading branch information
Julien Duchesne authored Apr 26, 2019
2 parents f871b23 + da8ba98 commit 4eebbc0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ func (config *TGFConfig) SetDefaultValues(ssmParameterFolder, location, files st
}

var reVersion = regexp.MustCompile(`(?P<version>\d+\.\d+(?:\.\d+){0,1})`)
var reVersionWithEndMarkers = regexp.MustCompile(`^` + reVersion.String() + `$`)

// https://regex101.com/r/ZKt4OP/5
var reImage = regexp.MustCompile(`^(?P<image>.*?)(?::(?:` + reVersion.String() + `(?:(?P<sep>[\.-])(?P<spec>.+))?|(?P<fix>.+)))?$`)
Expand Down Expand Up @@ -284,6 +285,13 @@ func (config *TGFConfig) Validate() (errors []error) {
return
}

// IsPartialVersion returns true if the given version is partial (x.x instead of semver's x.x.x)
func (config *TGFConfig) IsPartialVersion() bool {
return config.ImageVersion != nil &&
reVersionWithEndMarkers.MatchString(*config.ImageVersion) &&
strings.Count(*config.ImageVersion, ".") == 1
}

// GetImageName returns the actual image name
func (config *TGFConfig) GetImageName() string {
var suffix string
Expand Down
50 changes: 50 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,56 @@ func TestParseAliases(t *testing.T) {
}
}

func TestIsPartialVersion(t *testing.T) {
tests := []struct {
name string
version *string
isPartial bool
}{
{
"nil version",
nil,
false,
},
{
"partial",
aws.String("2.1"),
true,
},
{
"full",
aws.String("2.1.2"),
false,
},
{
"non-semver",
aws.String("stuff"),
false,
},
{
"partial-letters",
aws.String("a.b"),
false,
},
{
"partial with tag (this is not a real version, TGF would give a warning)",
aws.String("2.1-k8s"),
false,
},
{
"partial with non-semver word",
aws.String("hello 2.1"),
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
config := &TGFConfig{ImageVersion: tt.version}
assert.Equal(t, tt.isPartial, config.IsPartialVersion())
})
}
}

func writeSSMConfig(parameterFolder, parameterKey, parameterValue string) {
fullParameterKey := fmt.Sprintf("%s/%s", parameterFolder, parameterKey)
client := getSSMClient()
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func main() {
}

imageName := config.GetImageName()
if lastRefresh(imageName) > config.Refresh || !checkImage(imageName) || refresh {
if lastRefresh(imageName) > config.Refresh || config.IsPartialVersion() || !checkImage(imageName) || refresh {
refreshImage(imageName)
}

Expand Down

0 comments on commit 4eebbc0

Please sign in to comment.