Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
upstream fixes for update bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
verdverm committed May 14, 2020
1 parent 03f3c23 commit fd4f2ca
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 25 deletions.
19 changes: 19 additions & 0 deletions .hof/Cli/cmd/mvs/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func RootPersistentPreRun(args []string) (err error) {
return err
}

func RootPersistentPostRun(args []string) (err error) {

PrintUpdateAvailable()

return err
}

var RootCmd = &cobra.Command{

Use: "mvs",
Expand All @@ -59,6 +66,18 @@ var RootCmd = &cobra.Command{
ga.SendGaEvent("root", "<omit>", 0)

},

PersistentPostRun: func(cmd *cobra.Command, args []string) {
var err error

// Argument Parsing

err = RootPersistentPostRun(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

func init() {
Expand Down
37 changes: 25 additions & 12 deletions .hof/Cli/cmd/mvs/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
var UpdateLong = `Print the build version for mvs`

var (
UpdateCheckFlag bool
UpdateCheckFlag bool
UpdateVersionFlag string

UpdateStarted bool
UpdateErrored bool
Expand All @@ -32,10 +33,11 @@ var (

func init() {
UpdateCmd.Flags().BoolVarP(&UpdateCheckFlag, "check", "", false, "set to only check for an update")
UpdateCmd.Flags().StringVarP(&UpdateVersionFlag, "version", "v", "", "the version to update to")
}

const updateMessage = `
Updates available. v%s -> %s (latest)
Updates available. v%s -> %s
run 'mvs update' to get the latest.
Expand All @@ -53,6 +55,7 @@ var UpdateCmd = &cobra.Command{

PreRun: func(cmd *cobra.Command, args []string) {
ga.SendGaEvent("update", "<omit>", 0)

},

Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -65,15 +68,15 @@ var UpdateCmd = &cobra.Command{

// Semver Check?
cur := ProgramVersion{Version: "v" + verinfo.Version}
if latest.Version == cur.Version || cur.Version == "vLocal" {
if latest.Version == cur.Version || (UpdateVersionFlag == "" && cur.Version == "vLocal") {
return
} else {
if UpdateCheckFlag {
return
}
}

err = InstallLatest()
err = InstallUpdate()
if err != nil {
fmt.Println(err)
os.Exit(-1)
Expand All @@ -100,11 +103,16 @@ func CheckUpdate(manual bool) (ver ProgramVersion, err error) {
cur := ProgramVersion{Version: "v" + verinfo.Version}

checkURL := "https://api.github.com/repos/hofstadter-io/mvs/releases/latest"
if UpdateVersionFlag != "" {
checkURL = "https://api.github.com/repos/hofstadter-io/mvs/releases/tags/" + UpdateVersionFlag
manual = true
}

req := gorequest.New().Get(checkURL).
Query("current=" + cur.Version).
Query("manual=" + fmt.Sprint(manual))
resp, b, errs := req.EndBytes()
req := gorequest.New()
if os.Getenv("GITHUB_TOKEN") != "" {
req = req.SetBasicAuth("github-token", os.Getenv("GITHUB_TOKEN"))
}
resp, b, errs := req.Get(checkURL).EndBytes()
UpdateErrored = true

check := "http2: server sent GOAWAY and closed the connection"
Expand All @@ -118,6 +126,7 @@ func CheckUpdate(manual bool) (ver ProgramVersion, err error) {
}
if resp.StatusCode >= 400 {
if resp.StatusCode == 404 {
fmt.Println("404?!", checkURL)
return ver, fmt.Errorf("No releases available :[")
}
return ver, fmt.Errorf("Bad Request: " + string(b))
Expand Down Expand Up @@ -157,7 +166,7 @@ func CheckUpdate(manual bool) (ver ProgramVersion, err error) {
UpdateChecked = true

// Semver Check?
if ver.Version != cur.Version && cur.Version != "vLocal" {
if ver.Version != cur.Version && (manual || cur.Version != "vLocal") {
UpdateAvailable = &ver
aI, ok := gh["assets"]
if ok {
Expand All @@ -184,7 +193,7 @@ func PrintUpdateAvailable() {
}
}

func InstallLatest() (err error) {
func InstallUpdate() (err error) {
fmt.Printf("Installing mvs@%s\n", UpdateAvailable.Version)

if UpdateData == nil {
Expand Down Expand Up @@ -263,8 +272,12 @@ func InstallLatest() (err error) {
}

func downloadAndInstall(url string) error {
req := gorequest.New().Get(url)
resp, content, errs := req.EndBytes()
req := gorequest.New()
if os.Getenv("GITHUB_TOKEN") != "" {
req = req.SetBasicAuth("github-token", os.Getenv("GITHUB_TOKEN"))
}

resp, content, errs := req.Get(url).EndBytes()

check := "http2: server sent GOAWAY and closed the connection"
if len(errs) != 0 && !strings.Contains(errs[0].Error(), check) {
Expand Down
19 changes: 19 additions & 0 deletions cmd/mvs/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ func RootPersistentPreRun(args []string) (err error) {
return err
}

func RootPersistentPostRun(args []string) (err error) {

PrintUpdateAvailable()

return err
}

var RootCmd = &cobra.Command{

Use: "mvs",
Expand All @@ -59,6 +66,18 @@ var RootCmd = &cobra.Command{
ga.SendGaEvent("root", "<omit>", 0)

},

PersistentPostRun: func(cmd *cobra.Command, args []string) {
var err error

// Argument Parsing

err = RootPersistentPostRun(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}

func init() {
Expand Down
37 changes: 25 additions & 12 deletions cmd/mvs/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
var UpdateLong = `Print the build version for mvs`

var (
UpdateCheckFlag bool
UpdateCheckFlag bool
UpdateVersionFlag string

UpdateStarted bool
UpdateErrored bool
Expand All @@ -32,10 +33,11 @@ var (

func init() {
UpdateCmd.Flags().BoolVarP(&UpdateCheckFlag, "check", "", false, "set to only check for an update")
UpdateCmd.Flags().StringVarP(&UpdateVersionFlag, "version", "v", "", "the version to update to")
}

const updateMessage = `
Updates available. v%s -> %s (latest)
Updates available. v%s -> %s
run 'mvs update' to get the latest.
Expand All @@ -53,6 +55,7 @@ var UpdateCmd = &cobra.Command{

PreRun: func(cmd *cobra.Command, args []string) {
ga.SendGaEvent("update", "<omit>", 0)

},

Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -65,15 +68,15 @@ var UpdateCmd = &cobra.Command{

// Semver Check?
cur := ProgramVersion{Version: "v" + verinfo.Version}
if latest.Version == cur.Version || cur.Version == "vLocal" {
if latest.Version == cur.Version || (UpdateVersionFlag == "" && cur.Version == "vLocal") {
return
} else {
if UpdateCheckFlag {
return
}
}

err = InstallLatest()
err = InstallUpdate()
if err != nil {
fmt.Println(err)
os.Exit(-1)
Expand All @@ -100,11 +103,16 @@ func CheckUpdate(manual bool) (ver ProgramVersion, err error) {
cur := ProgramVersion{Version: "v" + verinfo.Version}

checkURL := "https://api.github.com/repos/hofstadter-io/mvs/releases/latest"
if UpdateVersionFlag != "" {
checkURL = "https://api.github.com/repos/hofstadter-io/mvs/releases/tags/" + UpdateVersionFlag
manual = true
}

req := gorequest.New().Get(checkURL).
Query("current=" + cur.Version).
Query("manual=" + fmt.Sprint(manual))
resp, b, errs := req.EndBytes()
req := gorequest.New()
if os.Getenv("GITHUB_TOKEN") != "" {
req = req.SetBasicAuth("github-token", os.Getenv("GITHUB_TOKEN"))
}
resp, b, errs := req.Get(checkURL).EndBytes()
UpdateErrored = true

check := "http2: server sent GOAWAY and closed the connection"
Expand All @@ -118,6 +126,7 @@ func CheckUpdate(manual bool) (ver ProgramVersion, err error) {
}
if resp.StatusCode >= 400 {
if resp.StatusCode == 404 {
fmt.Println("404?!", checkURL)
return ver, fmt.Errorf("No releases available :[")
}
return ver, fmt.Errorf("Bad Request: " + string(b))
Expand Down Expand Up @@ -157,7 +166,7 @@ func CheckUpdate(manual bool) (ver ProgramVersion, err error) {
UpdateChecked = true

// Semver Check?
if ver.Version != cur.Version && cur.Version != "vLocal" {
if ver.Version != cur.Version && (manual || cur.Version != "vLocal") {
UpdateAvailable = &ver
aI, ok := gh["assets"]
if ok {
Expand All @@ -184,7 +193,7 @@ func PrintUpdateAvailable() {
}
}

func InstallLatest() (err error) {
func InstallUpdate() (err error) {
fmt.Printf("Installing mvs@%s\n", UpdateAvailable.Version)

if UpdateData == nil {
Expand Down Expand Up @@ -263,8 +272,12 @@ func InstallLatest() (err error) {
}

func downloadAndInstall(url string) error {
req := gorequest.New().Get(url)
resp, content, errs := req.EndBytes()
req := gorequest.New()
if os.Getenv("GITHUB_TOKEN") != "" {
req = req.SetBasicAuth("github-token", os.Getenv("GITHUB_TOKEN"))
}

resp, content, errs := req.Get(url).EndBytes()

check := "http2: server sent GOAWAY and closed the connection"
if len(errs) != 0 && !strings.Contains(errs[0].Error(), check) {
Expand Down
2 changes: 1 addition & 1 deletion cue.mods
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module github.com/hofstadter-io/mvs
cue master

require (
github.com/hofstadter-io/hofmod-cli v0.5.4
github.com/hofstadter-io/hofmod-cli v0.5.5
)
2 changes: 2 additions & 0 deletions cue.sums
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ github.com/hofstadter-io/hofmod-cli v0.5.3 h1:9QcITvHncO6lWHezRnM1YXkVTula6sfsHE
github.com/hofstadter-io/hofmod-cli v0.5.3/cue.mods h1:8TVLRMLOvfcVRZu6NqDr4VFmvuw/9Ca7YpCMo1fTRmU=
github.com/hofstadter-io/hofmod-cli v0.5.4 h1:bO72JKO70dnmRBOV/c9IbTXQZuhsParhuwEhtL7+EdU=
github.com/hofstadter-io/hofmod-cli v0.5.4/cue.mods h1:8TVLRMLOvfcVRZu6NqDr4VFmvuw/9Ca7YpCMo1fTRmU=
github.com/hofstadter-io/hofmod-cli v0.5.5 h1:U39psc0wrKEEdYiNZ5+9b+50PyxFLCeQ7b3mC64SBas=
github.com/hofstadter-io/hofmod-cli v0.5.5/cue.mods h1:8TVLRMLOvfcVRZu6NqDr4VFmvuw/9Ca7YpCMo1fTRmU=

0 comments on commit fd4f2ca

Please # to comment.