Skip to content
Merged
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
19 changes: 12 additions & 7 deletions pkg/core/engine/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import (
"encoding/json"
"fmt"
"io"
"strings"
"time"

"github.com/sirupsen/logrus"
"github.com/updatecli/updatecli/pkg/core/httpclient"
"github.com/updatecli/updatecli/pkg/core/version"
)

var (
// versionHTTPEndpoint is the URL to check for the latest version of updatecli
versionHTTPEndpoint string = "https://www.updatecli.io/changelogs/updatecli/_index.json"
)
// versionHTTPEndpoint is the URL to check for the latest version of updatecli
var versionHTTPEndpoint string = "https://www.updatecli.io/changelogs/updatecli/_index.json"

// CheckLatestPublishedVersion check if the currently used version is the latest version
// available
func CheckLatestPublishedVersion() error {

client := httpclient.NewThrottledRetryClient(1*time.Second, 1)

type versionData struct {
Expand Down Expand Up @@ -54,12 +52,19 @@ func CheckLatestPublishedVersion() error {
return fmt.Errorf("unable to parse the latest version of updatecli: %v", err)
}

if data.Latest.Tag == version.Version {
sanitizeVersion := func(v string) string {
s := strings.TrimSpace(v)
s = strings.TrimPrefix(s, "v")

return s
}

if sanitizeVersion(data.Latest.Tag) == sanitizeVersion(version.Version) {
return nil
}

logrus.Infof("\n---")
logrus.Infof("A new version of updatecli is available: %s (current: %q)", data.Latest.Tag, version.Version)
logrus.Infof("A new version of updatecli is available: %s (current: %s)", data.Latest.Tag, version.Version)
logrus.Infof("Changelog available at: www.updatecli.io/changelogs/updatecli/changelogs/%s/", data.Latest.Tag)
logrus.Infof("---")

Expand Down
Loading