-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
func versionCheck() error { | ||
if VERSION == "development" { | ||
return nil | ||
} | ||
|
||
res, err := http.Get("https://api.github.com/repos/synadia-io/nex/releases/latest") | ||
if err != nil { | ||
return err | ||
} | ||
defer res.Body.Close() | ||
|
||
b, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
payload := make(map[string]interface{}) | ||
err = json.Unmarshal(b, &payload) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
latestTag, ok := payload["tag_name"].(string) | ||
if !ok { | ||
return errors.New("error parsing tag_name") | ||
} | ||
|
||
if latestTag != VERSION { | ||
fmt.Printf(`================================================================ | ||
🎉 There is a newer version [v%s] of the NEX CLI available 🎉 | ||
To update, run: | ||
curl -sSf https://nex.synadia.com/install.sh | sh | ||
================================================================ | ||
`, | ||
latestTag) | ||
} | ||
|
||
return nil | ||
} |