From 8cf393051801d07c67d8ebd15297eb6e8b34f7ba Mon Sep 17 00:00:00 2001 From: Roxie Gibson Date: Fri, 3 Sep 2021 19:57:15 +0100 Subject: [PATCH] fix: tag sorting as map is unsorted --- catalogue/catalogue.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/catalogue/catalogue.go b/catalogue/catalogue.go index 144ab06c..b33b1fba 100644 --- a/catalogue/catalogue.go +++ b/catalogue/catalogue.go @@ -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