fix: tag sorting as map is unsorted
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Roxie Gibson 2021-09-03 19:57:15 +01:00
parent b1d4f12e7d
commit 8cf3930518
Signed by untrusted user: roxxers
GPG Key ID: 5D0140EDEE123F4D
1 changed files with 15 additions and 4 deletions

View File

@ -12,8 +12,10 @@ import (
"coopcloud.tech/abra/config"
"coopcloud.tech/abra/web"
"coopcloud.tech/tagcmp"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/sirupsen/logrus"
)
type Image struct {
@ -111,12 +113,21 @@ func (a App) EnsureVersion(version string) error {
// LatestVersion returns the latest version of the app
func (a App) LatestVersion() string {
var latestVersion string
var latestTag tagcmp.Tag
for tag := range a.Versions {
// apps.json versions are sorted so the last key is latest
latestVersion = tag
currentTag, err := tagcmp.Parse(tag)
if err != nil {
logrus.Warn(fmt.Errorf("%s is not a valid tag: %s", tag, err))
}
if latestTag == (tagcmp.Tag{}) {
latestTag = currentTag
} else {
if latestTag.IsLessThan(currentTag) {
latestTag = currentTag
}
}
}
return latestVersion
return latestTag.String()
}
type Name = string