fix: tag sorting as map is unsorted #66

Closed
roxxers wants to merge 1 commits from fix/tag-sort into main

View File

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