Skip to content
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 remote version check #1735

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

uthark
Copy link

@uthark uthark commented Apr 5, 2023

Fixes #883

@uthark uthark force-pushed the oatamanenko/version-check branch 2 times, most recently from 6abeee1 to 6fc0d18 Compare April 5, 2023 04:37
@uthark uthark force-pushed the oatamanenko/version-check branch from 6fc0d18 to cc98764 Compare April 5, 2023 04:38
@uthark
Copy link
Author

uthark commented Apr 5, 2023

@wata727 please take a look

@bendrucker bendrucker self-requested a review April 5, 2023 17:44

func getLatestVersion() (*github.RepositoryRelease, error) {
ghClient := github.NewClient(nil)
releases, _, err := ghClient.Repositories.ListReleases(context.Background(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep all args on one line or if that line gets too long each arg should be its own line. Mixing both style is awkward.

}

func getLatestVersion() (*github.RepositoryRelease, error) {
ghClient := github.NewClient(nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be authenticated if a token is provided, for rate limiting purposes. See plugin.newGitHubClient.

}

// GitHub sorts releases results. Select first non-prerelease version and return it.
for i := range releases {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for _, release := range


// Checks GitHub releases and prints new version, if current version is outdated.
// requires GitHub releases to follow semver.
func (cli *CLI) printLatestReleaseVersion() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a way to disable this, e.g., for users who want to run TFLint offline. See https://developer.hashicorp.com/terraform/cli/commands#upgrade-and-security-bulletin-checks.

}
compare := tflint.Version.Compare(latestVersion)
if compare < 0 {
fmt.Fprintf(cli.outStream, "New version available: %s\n", *latest.HTMLURL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terraform prints, for example:

Your version of Terraform is out of date! The latest version
is 1.4.4. You can update by downloading from https://www.terraform.io/downloads.html

It would be nice to do something similar, namely:

  • The new version
  • The URL

You already have the latter here.


func getLatestVersion() (*github.RepositoryRelease, error) {
ghClient := github.NewClient(nil)
releases, _, err := ghClient.Repositories.ListReleases(context.Background(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use /releases/latest and not list releases:

https://docs.github.com/en/rest/releases/releases?apiVersion=2022-11-28#get-the-latest-release

That will handle excluding prereleases and drafts. Alternatively, if we had to use list, we should be fetching smaller pages than the 30 returned by default.

@wata727
Copy link
Member

wata727 commented Sep 3, 2023

@uthark Any updates? Still interested in finishing this?

@uthark
Copy link
Author

uthark commented Sep 3, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Inform users when a new version is available
3 participants