Skip to content

Commit

Permalink
get latest version from github
Browse files Browse the repository at this point in the history
  • Loading branch information
pmenglund committed Oct 25, 2023
1 parent 178e6a2 commit a792d5a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,16 @@ func newVersionCmd() *cobra.Command {
return &cmd
}

// TODO change to HTTPS

const VersionURL = "http://rockset.sh/install/version.json"

type Versions struct {
Stable string `json:"stable"`
Beta string `json:"beta"`
type githubResponse struct {
Name string `json:"name"`
}

func VersionCheck(ctx context.Context, ch chan string) {
func GithubVersionCheck(ctx context.Context, ch chan string) {
// always send something on the channel
defer func() { ch <- "" }()

request, err := http.NewRequestWithContext(ctx, http.MethodGet, VersionURL, nil)
request, err := http.NewRequestWithContext(ctx, http.MethodGet,
"https://api.github.com/repos/rockset/cli/releases/latest", nil)
if err != nil {
logger.Error("failed to create http request", "err", err)
return
Expand All @@ -84,14 +80,14 @@ func VersionCheck(ctx context.Context, ch chan string) {
return
}

var v Versions
var releases githubResponse
dec := json.NewDecoder(response.Body)
if err = dec.Decode(&v); err != nil {
if err = dec.Decode(&releases); err != nil {
logger.Error("failed to unmarshal json", "err", err)
return
}

if v.Stable != Version {
ch <- fmt.Sprintf("A new release of %s is available: %s → %s", tui.Rockset, Version, v.Stable)
if releases.Name != Version {
ch <- fmt.Sprintf("A new release of %s is available: %s → %s", tui.Rockset, Version, releases.Name)
}
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func main() {
}()

// kick off a version check in the background that will show up at the end of the run
go cmd.VersionCheck(versionCtx, version)
go cmd.GithubVersionCheck(versionCtx, version)

root := cmd.NewRootCmd(Version)
if err := root.ExecuteContext(ctx); err != nil {
Expand Down

0 comments on commit a792d5a

Please sign in to comment.