-
Notifications
You must be signed in to change notification settings - Fork 2k
Add update checker #282
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
Add update checker #282
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/vercel/turbo-site/Dh6z4ccGeZepNSmM7fnXywXYyeQq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty close, I guess could be just as easy to directly copy pscale's and then add the necessary config GetConfigDir functions to config_file.go
"https://api.github.com/repos/vercel/turborepo/releases/latest", | ||
) | ||
if newRelease != nil { | ||
color.Yellow("A new version of `create-turbo` is available! %s") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use util.printf
here.
This is also for turbo
and not create-turbo
color.Yellow("A new version of `create-turbo` is available! %s") | ||
fmt.Println("You can update by running: ") | ||
// TODO: show only one method depending on the user chosen package manager | ||
color.Cyan("yarn global add create-turbo Or npm i -g create-turbo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can move this message to after config is loaded so that we can give correct installation instructions based on the detected pacakge manager.
We also should not suggest global installation at the moment.
|
||
// ReleaseInfo stores information about a release | ||
type ReleaseInfo struct { | ||
VERSION string `json:"tag_name"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VERSION string `json:"tag_name"` | |
Version string `json:"tagName"` |
// ReleaseInfo stores information about a release | ||
type ReleaseInfo struct { | ||
VERSION string `json:"tag_name"` | ||
URL string `json:"html_url"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use camel case for consistency
return nil, err | ||
} | ||
req.Header.Set("Content-Type", "application/json; charset=utf-8") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set additional Github headers like planetscale https://github.com/planetscale/cli/blob/main/internal/update/update.go#L157
} | ||
req.Header.Set("Content-Type", "application/json; charset=utf-8") | ||
|
||
client := &http.Client{Timeout: time.Second * 10} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use github token to auth the request if possible https://github.com/planetscale/cli/blob/main/internal/update/update.go#L159-L170
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is possible. But should we store it in a .env file or is there any other approach you have in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use os.GetEnv like planet scale does, if it's not there that's fine. don't worry about .env
// used to decide whether to check for a new version or not. | ||
type StateEntry struct { | ||
CheckedForUpdateAt time.Time `yaml:"checked_for_update_at"` | ||
LatestRelease ReleaseInfo `yaml:"latest_release"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use dash case instead of snake case for these.
return nil, err | ||
} | ||
|
||
if versionGreaterThan(releaseInfo.VERSION, currentVersion) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if versionGreaterThan(releaseInfo.VERSION, currentVersion) { | |
if versionGreaterThan(releaseInfo.Version, currentVersion) { |
return err | ||
} | ||
|
||
func versionGreaterThan(v, w string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify to just this https://github.com/planetscale/cli/blob/main/internal/update/update.go#L122-L146
Let's also allow for TURBO_NO_UPDATE_NOTIFIER
environment variable https://github.com/planetscale/cli/blob/main/internal/update/update.go#L96-L100
@jaredpalmer thanks for the review, I'll start working on the suggested changes soon. |
Clsoing this to open a new one with all the changes |
Before it showed only some issues in the dev server, now it aggregates issues from all sources
…#282) This fixes `http://localhost:3000/layouts/electronics` trying to load `http://localhost:3000/layouts/_chunks/*` when it shows the fallback page.
closes #178