Skip to content

Fix core list command not returning latest available version #1409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion commands/core/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package core

import (
"fmt"
"sort"
"strings"

Expand Down Expand Up @@ -58,14 +59,20 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) {
}

if platformRelease != nil {
latest := platform.GetLatestRelease()
if latest == nil {
return nil, fmt.Errorf(tr("can't find latest release of core %s", platform))
}

if req.UpdatableOnly {
if latest := platform.GetLatestRelease(); latest == nil || latest == platformRelease {
if latest == platformRelease {
continue
}
}

rpcPlatform := commands.PlatformReleaseToRPC(platformRelease)
rpcPlatform.Installed = platformRelease.Version.String()
rpcPlatform.Latest = latest.Version.String()
res = append(res, rpcPlatform)
}
}
Expand Down
8 changes: 6 additions & 2 deletions i18n/data/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,10 @@ msgstr "can't find dependencies for platform %[1]s: %[2]w"
msgid "can't find latest release of %s"
msgstr "can't find latest release of %s"

#: commands/core/list.go:64
msgid "can't find latest release of core %s"
msgstr "can't find latest release of core %s"

#: arduino/sketch/sketch.go:101
msgid "can't find main Sketch file in %s"
msgstr "can't find main Sketch file in %s"
Expand Down Expand Up @@ -2630,7 +2634,7 @@ msgstr "invalid hash '%[1]s': %[2]s"
#: commands/compile/compile.go:93
#: commands/core/download.go:36
#: commands/core/install.go:35
#: commands/core/list.go:38
#: commands/core/list.go:39
#: commands/core/search.go:40
#: commands/core/uninstall.go:33
#: commands/core/upgrade.go:40
Expand Down Expand Up @@ -3306,7 +3310,7 @@ msgstr "unable to create a folder to save the sketch files"
msgid "unable to create the folder containing the item"
msgstr "unable to create the folder containing the item"

#: commands/core/list.go:33
#: commands/core/list.go:34
msgid "unable to find an instance with ID: %d"
msgstr "unable to find an instance with ID: %d"

Expand Down
14 changes: 7 additions & 7 deletions i18n/rice-box.go

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import hashlib
from git import Repo
from pathlib import Path
import semver


def test_core_search(run_command, httpserver):
Expand Down Expand Up @@ -753,3 +754,21 @@ def test_core_with_missing_custom_board_options_is_loaded(run_command, data_dir)
+ "skipping loading of boards arduino-beta-dev:platform_with_missing_custom_board_options:nessuno: "
+ "malformed custom board options"
) in res.stderr


def test_core_list_outdated_core(run_command):
assert run_command("update")

# Install an old core version
assert run_command("core install arduino:[email protected]")

res = run_command("core list --format json")

data = json.loads(res.stdout)
assert len(data) == 1
samd_core = data[0]
assert samd_core["installed"] == "1.8.6"
installed_version = semver.parse_version_info(samd_core["installed"])
latest_version = semver.parse_version_info(samd_core["latest"])
# Installed version must be older than latest
assert installed_version.compare(latest_version) == -1