Skip to content

Conversation

matlobocki
Copy link
Contributor

No description provided.

cmd/ax/main.go Outdated
addAlertCommand = alertCommand.Command("add", "Add new alert")
version = "dev"
version = "v0.3.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

So... do we change version manually after releases? Seems fiddly. cc @zefhemel

Copy link
Contributor

Choose a reason for hiding this comment

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

That doesn't seem like a good idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted to "dev"


release, _, err := client.Repositories.GetLatestRelease(context.Background(), "egnyte", "ax")
if err != nil {
fmt.Printf("Couldn't get a release information")
Copy link
Contributor

Choose a reason for hiding this comment

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

"Couldn't fetch release information"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied

cmd/ax/main.go Outdated
@@ -23,6 +23,7 @@ var (
alertCommand = kingpin.Command("alert", "Be alerted when logs match a query")
alertDCommand = kingpin.Command("alertd", "Be alerted when logs match a query")
versionCommand = kingpin.Command("version", "Show the ax version")
upgrade = kingpin.Command("upgrade", "Verify if there is a new version available")
Copy link
Contributor

Choose a reason for hiding this comment

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

Upgrade Ax if a new version is available

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied

cmd/ax/main.go Outdated
case "upgrade":
err := upgradeVersion()
if err != nil {
fmt.Println("Upgrade failed.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you want to actually print the error?

func getLatestReleaseData() *github.RepositoryRelease {
client := github.NewClient(nil)

release, _, err := client.Repositories.GetLatestRelease(context.Background(), "egnyte", "ax")
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to define egnyte and ax as top-level constants.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Applied


release, _, err := client.Repositories.GetLatestRelease(context.Background(), "egnyte", "ax")
if err != nil {
fmt.Printf("Couldn't get a release information")
Copy link
Contributor

Choose a reason for hiding this comment

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

I would really print the error message here too (%v)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied

for _, element := range release.Assets {
assetLink := element.GetBrowserDownloadurl("")
if strings.Contains(assetLink, runtime.GOOS) && strings.Contains(assetLink, runtime.GOARCH) {
assetDownloadLink = assetLink
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd just instantly return the value rather than keeping it in a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improved

return release.GetTagName()
}

func downloadFile(filepath string, url string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

filePath

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}

func upgradeVersion() error {
if latestVersion := getLatestReleaseTag(); version != latestVersion {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd probably do this to avoid a giant indented block:

latestVersion := getLatestReleaseTag()
if version == latestVersion {
   fmt.Println("Latest version is already installed.")
   return
}
// Upgrade case here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was considering it as I would the same in Python 😂 Im going to improve that.

return err
}
defer os.RemoveAll(extractionPath)
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, I'd just exit early (test negative case) to avoid giant if blocks.

if strings.ToLower(text) == "yes" || strings.ToLower(text) == "y" {
latestAssetURL := getLatestAssetLink()
downloadPath := "/tmp/egnyte_ax/ax.tar.gz"
extractionPath := "/tmp/egnyte_ax/"
Copy link
Contributor

Choose a reason for hiding this comment

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


// switch old binary with a new one
currentBinaryPath, _ := osext.Executable()
err = os.Rename(extractionPath+"ax", currentBinaryPath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I suppose if you use TempFile and TempDir this may not work (rename won't work between different partitions). But you could copy the file and delete it afterwards.


func getLatestAssetLink() string {
release := getLatestReleaseData()
var assetDownloadLink string
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this means that assetDownloadLink could be an empty string.

if strings.ToLower(text) == "yes" || strings.ToLower(text) == "y" {
latestAssetURL := getLatestAssetLink()
downloadPath := "/tmp/egnyte_ax/ax.tar.gz"
extractionPath := "/tmp/egnyte_ax/"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should use TempFile and possibly TempDir for this.

if latestVersion := getLatestReleaseTag(); version != latestVersion {
fmt.Printf("New version detected. Current version: %s. Latest version: %s\n", version, latestVersion)
inputScanner := bufio.NewScanner(os.Stdin)
fmt.Print("Do you want to upgrade an Ax to its latest version? (yes/no): ")
Copy link
Contributor

Choose a reason for hiding this comment

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

"Do you want to upgrade Ax to the latest version?"

extractionPath := "/tmp/egnyte_ax/"

if _, err := os.Stat(extractionPath); os.IsNotExist(err) {
os.Mkdir(extractionPath, 0755)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably want to at least crash if this fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually if you use TempDir this won't matter.

// currentBinaryPath, _ := osext.Executable()
// if err := os.Rename(extractionPath+"ax", currentBinaryPath); err != nil {
// return err
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

So we don't actually perform the upgrade right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was testing something and missed this :( uncommented

@matlobocki
Copy link
Contributor Author

Code review comments applied.

@matlobocki matlobocki force-pushed the include_latest_release_version branch from fbc5df8 to e2309c4 Compare April 20, 2018 12:45
if err != nil {
return err
}
downloadPath := fmt.Sprintf("%s/ax.tar.gz", extractionPath)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be still improved but the logic in the downloadFile has to be improved as well.

@zefhemel zefhemel merged commit 84f8502 into master Apr 23, 2018
@zefhemel zefhemel deleted the include_latest_release_version branch April 23, 2018 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants