fix: tag sorting as map is unsorted
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
b1d4f12e7d
commit
8cf3930518
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue