mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-18 16:06:58 +00:00
bug: Fix version list (#1323)
* 🐛 Fix version list First version in the list is the latest one. Alos moves the check for same version above the current place, so it can check before asking if you want to update to the same version Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com> * 🌱 Rework versioning for upgrade Use the semver lib to parse the versions into a proper collection where it can be parsed and versions compared and sorted properly Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com> * 🤖 lint Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com> --------- Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
@@ -8,18 +8,18 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
events "github.com/kairos-io/kairos-sdk/bus"
|
||||
"github.com/kairos-io/kairos/v2/pkg/config"
|
||||
"github.com/kairos-io/kairos/v2/pkg/config/collector"
|
||||
|
||||
"github.com/kairos-io/kairos-sdk/utils"
|
||||
"github.com/kairos-io/kairos/v2/internal/bus"
|
||||
"github.com/kairos-io/kairos/v2/pkg/config"
|
||||
"github.com/kairos-io/kairos/v2/pkg/config/collector"
|
||||
"github.com/kairos-io/kairos/v2/pkg/github"
|
||||
"github.com/mudler/go-pluggable"
|
||||
)
|
||||
|
||||
func ListReleases() []string {
|
||||
releases := []string{}
|
||||
func ListReleases() semver.Collection {
|
||||
var releases semver.Collection
|
||||
|
||||
bus.Manager.Response(events.EventAvailableReleases, func(p *pluggable.Plugin, r *pluggable.EventResponse) {
|
||||
if err := json.Unmarshal([]byte(r.Data), &releases); err != nil {
|
||||
@@ -55,7 +55,13 @@ func Upgrade(
|
||||
return fmt.Errorf("no releases found")
|
||||
}
|
||||
|
||||
version = releases[len(releases)-1]
|
||||
// Using Original here because the parsing removes the v as its a semver. But it stores the original full version there
|
||||
version = releases[0].Original()
|
||||
|
||||
if utils.Version() == version && !force {
|
||||
fmt.Printf("version %s already installed. use --force to force upgrade\n", version)
|
||||
return nil
|
||||
}
|
||||
msg := fmt.Sprintf("Latest release is %s\nAre you sure you want to upgrade to this release? (y/n)", version)
|
||||
reply, err := promptBool(events.YAMLPrompt{Prompt: msg, Default: "y"})
|
||||
if err != nil {
|
||||
@@ -66,11 +72,6 @@ func Upgrade(
|
||||
}
|
||||
}
|
||||
|
||||
if utils.Version() == version && !force {
|
||||
fmt.Println("version already installed. use --force to force upgrade")
|
||||
return nil
|
||||
}
|
||||
|
||||
discoveredImage := ""
|
||||
bus.Manager.Response(events.EventVersionImage, func(p *pluggable.Plugin, r *pluggable.EventResponse) {
|
||||
discoveredImage = r.Data
|
||||
|
Reference in New Issue
Block a user