Skip to content

Return exit code 0 when a core is already up to date #2207

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
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
20 changes: 18 additions & 2 deletions internal/cli/core/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool) {
response, err := core.PlatformUpgrade(context.Background(), r, feedback.ProgressBar(), feedback.TaskProgress())
warningMissingIndex(response)
if err != nil {
if errors.Is(err, &arduino.PlatformAlreadyAtTheLatestVersionError{}) {
feedback.Print(err.Error())
var alreadyAtLatestVersionErr *arduino.PlatformAlreadyAtTheLatestVersionError
if errors.As(err, &alreadyAtLatestVersionErr) {
feedback.Warning(err.Error())
continue
}

Expand All @@ -122,4 +123,19 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool) {
if hasBadArguments {
feedback.Fatal(tr("Some upgrades failed, please check the output for details."), feedback.ErrBadArgument)
}

feedback.PrintResult(&platformUpgradeResult{})
}

// This is needed so we can print warning messages in case users use --format json
type platformUpgradeResult struct{}

// Data implements feedback.Result.
func (r *platformUpgradeResult) Data() interface{} {
return r
}

// String implements feedback.Result.
func (r *platformUpgradeResult) String() string {
return ""
}
8 changes: 4 additions & 4 deletions internal/integrationtest/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,16 +1041,16 @@ func TestCoreUpgradeWarningWithPackageInstalledButNotIndexed(t *testing.T) {
_, _, err = cli.Run("core", "install", "test:[email protected]", "--additional-urls="+url)
require.NoError(t, err)
//upgrade without index fires a warning
_, jsonStderr, _ := cli.Run("core", "upgrade", "test:x86", "--format", "json")
requirejson.Query(t, jsonStderr, ".warnings[]", `"missing package index for test:x86, future updates cannot be guaranteed"`)
jsonStdout, _, _ := cli.Run("core", "upgrade", "test:x86", "--format", "json")
requirejson.Query(t, jsonStdout, ".warnings[]", `"missing package index for test:x86, future updates cannot be guaranteed"`)
})

// removing installed.json
installedJson := cli.DataDir().Join("packages", "test", "hardware", "x86", "1.0.0", "installed.json")
require.NoError(t, os.Remove(installedJson.String()))

t.Run("missing both installed.json and additional-urls", func(t *testing.T) {
_, jsonStderr, _ := cli.Run("core", "upgrade", "test:x86", "--format", "json")
requirejson.Query(t, jsonStderr, ".warnings[]", `"missing package index for test:x86, future updates cannot be guaranteed"`)
jsonStdout, _, _ := cli.Run("core", "upgrade", "test:x86", "--format", "json")
requirejson.Query(t, jsonStdout, ".warnings[]", `"missing package index for test:x86, future updates cannot be guaranteed"`)
})
}