@@ -22,13 +22,15 @@ import (
2222 "sync"
2323 "time"
2424
25+ "github.com/Masterminds/semver/v3"
2526 "github.com/arduino/arduino-cli/commands"
2627 "github.com/arduino/arduino-cli/commands/cmderrors"
2728 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2829 "github.com/sirupsen/logrus"
2930
3031 "github.com/arduino/arduino-app-cli/internal/helpers"
3132 "github.com/arduino/arduino-app-cli/internal/orchestrator"
33+ "github.com/arduino/arduino-app-cli/internal/orchestrator/config"
3234 "github.com/arduino/arduino-app-cli/internal/update"
3335)
3436
@@ -53,7 +55,7 @@ func setConfig(ctx context.Context, srv rpc.ArduinoCoreServiceServer) error {
5355}
5456
5557// ListUpgradablePackages implements ServiceUpdater.
56- func (a * ArduinoPlatformUpdater ) ListUpgradablePackages (ctx context.Context , _ func (update.UpgradablePackage ) bool ) ([]update.UpgradablePackage , error ) {
58+ func (a * ArduinoPlatformUpdater ) ListUpgradablePackages (cfg config. Configuration , ctx context.Context , _ func (update.UpgradablePackage ) bool ) ([]update.UpgradablePackage , error ) {
5759 if ! a .lock .TryLock () {
5860 return nil , update .ErrOperationAlreadyInProgress
5961 }
@@ -112,15 +114,51 @@ func (a *ArduinoPlatformUpdater) ListUpgradablePackages(ctx context.Context, _ f
112114 return nil , nil // No platform found
113115 }
114116
115- if platformSummary .GetLatestVersion () == platformSummary .GetInstalledVersion () {
116- return nil , nil // No update available
117+ installedVersionString := platformSummary .GetInstalledVersion ()
118+
119+ installedV , err := semver .NewVersion (installedVersionString )
120+ if err != nil {
121+ slog .Warn ("Failed to parse installed version" , "version" , installedVersionString , "error" , err )
122+ return nil , nil
123+ }
124+
125+ var maxMajor uint64
126+ if cfg .MaxAllowedMajorVersion > 0 {
127+ maxMajor = uint64 (cfg .MaxAllowedMajorVersion )
117128 }
129+ var bestUpdateV * semver.Version
130+
131+ allReleases := platformSummary .GetReleases ()
132+ for versionString := range allReleases {
133+ candidateV , err := semver .NewVersion (versionString )
134+ if err != nil {
135+ slog .Debug ("Skipping unparsable version" , "version" , versionString , "error" , err )
136+ continue
137+ }
118138
139+ if candidateV .Major () > maxMajor {
140+ continue
141+ }
142+
143+ if ! candidateV .GreaterThan (installedV ) {
144+ continue
145+ }
146+
147+ if bestUpdateV == nil || candidateV .GreaterThan (bestUpdateV ) {
148+ bestUpdateV = candidateV
149+ }
150+ }
151+ if bestUpdateV == nil {
152+ slog .Debug ("No suitable updates found within major version constraint" )
153+ return nil , nil
154+ }
155+ slog .Debug (" bestUpdateV.Original()" , bestUpdateV .Original (), "" )
156+ slog .Debug (" bestUpdateV.String()" , bestUpdateV .String (), "" )
119157 return []update.UpgradablePackage {{
120158 Type : update .Arduino ,
121159 Name : "arduino:zephyr" ,
122160 FromVersion : platformSummary .GetInstalledVersion (),
123- ToVersion : platformSummary . GetLatestVersion (),
161+ ToVersion : bestUpdateV . Original (),
124162 }}, nil
125163}
126164
0 commit comments