@@ -22,13 +22,15 @@ import (
2222 "log/slog"
2323 "sync"
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 }
@@ -121,15 +123,51 @@ func (a *ArduinoPlatformUpdater) ListUpgradablePackages(ctx context.Context, _ f
121123 return nil , nil // No platform found
122124 }
123125
124- if platformSummary .GetLatestVersion () == platformSummary .GetInstalledVersion () {
125- return nil , nil // No update available
126+ installedVersionString := platformSummary .GetInstalledVersion ()
127+
128+ installedV , err := semver .NewVersion (installedVersionString )
129+ if err != nil {
130+ slog .Warn ("Failed to parse installed version" , "version" , installedVersionString , "error" , err )
131+ return nil , nil
132+ }
133+
134+ var maxMajor uint64
135+ if cfg .MaxAllowedMajorVersion > 0 {
136+ maxMajor = uint64 (cfg .MaxAllowedMajorVersion )
126137 }
138+ var bestUpdateV * semver.Version
139+
140+ allReleases := platformSummary .GetReleases ()
141+ for versionString := range allReleases {
142+ candidateV , err := semver .NewVersion (versionString )
143+ if err != nil {
144+ slog .Debug ("Skipping unparsable version" , "version" , versionString , "error" , err )
145+ continue
146+ }
127147
148+ if candidateV .Major () > maxMajor {
149+ continue
150+ }
151+
152+ if ! candidateV .GreaterThan (installedV ) {
153+ continue
154+ }
155+
156+ if bestUpdateV == nil || candidateV .GreaterThan (bestUpdateV ) {
157+ bestUpdateV = candidateV
158+ }
159+ }
160+ if bestUpdateV == nil {
161+ slog .Debug ("No suitable updates found within major version constraint" )
162+ return nil , nil
163+ }
164+ slog .Debug (" bestUpdateV.Original()" , bestUpdateV .Original (), "" )
165+ slog .Debug (" bestUpdateV.String()" , bestUpdateV .String (), "" )
128166 return []update.UpgradablePackage {{
129167 Type : update .Arduino ,
130168 Name : "arduino:zephyr" ,
131169 FromVersion : platformSummary .GetInstalledVersion (),
132- ToVersion : platformSummary . GetLatestVersion (),
170+ ToVersion : bestUpdateV . Original (),
133171 }}, nil
134172}
135173
0 commit comments