use go-cmd/cmd

This commit is contained in:
Jeff Carr 2024-11-08 06:45:12 -06:00
parent f189efd9d7
commit a68b3400a5
2 changed files with 38 additions and 34 deletions

View File

@ -6,6 +6,8 @@ import (
"path/filepath"
"strings"
"github.com/go-cmd/cmd"
"go.wit.com/lib/gui/repolist"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
@ -149,12 +151,12 @@ func doReleaseFindNext() bool {
// to insert the new version
func doPublishVersion() bool {
gopath := me.current.GoPath()
cmd := []string{"go", "get", "-v", gopath + "@" + me.release.version.String()}
log.Info("SHOULD RUN cmd HERE:", cmd)
docmd := []string{"go", "get", "-v", gopath + "@" + me.release.version.String()}
log.Info("SHOULD RUN cmd HERE:", docmd)
// right now, you can't publish this because the go.* files in this project are screwed up
if me.release.guireleaser == nil {
log.Info("CAN NOT SELF UPDATE HERE. cmd =", cmd)
log.Info("CAN NOT SELF UPDATE HERE. cmd =", docmd)
return false
}
homeDir, _ := os.UserHomeDir()
@ -163,37 +165,39 @@ func doPublishVersion() bool {
log.Info("go.sum must exist here")
me.release.guireleaser.Status.MakeRedomod()
}
var err error
var out string
if me.current.Status.IsPrivate() {
// do not self update private repos
err = nil
out = "This is a private repo and can not be self checked"
} else {
log.Info("This is a private repo and can not be self checked")
return true
}
// try to pull from google
var result cmd.Status
if gopath == "go.wit.com/apps/guireleaser" {
log.Info("CAN NOT SELF UPDATE. cmd =", cmd)
log.Info("CAN NOT SELF UPDATE. cmd =", docmd)
log.Info("go get must be run from somewhere else other than guireleaser")
err, ok, output := shell.RunCmd("", cmd)
log.Info("err =", err)
log.Info("ok =", ok)
log.Info("output =", output)
result = shell.PathRun("/home/jcarr/go/src/go.wit.com/apps/autotypist", docmd)
} else {
// publish go.mod & go.sum for use with go
os.Unsetenv("GO111MODULE")
log.Info("TRYING TO SELF UPDATE HERE. cmd =", cmd)
err, out = me.release.guireleaser.Status.RunCmd(cmd)
if gopath == "go.wit.com/apps/guireleaser" {
// ignore errors on updating myself
log.Info("IGNORE SELF UPDATE ERROR. cmd =", cmd)
err = nil
}
}
}
if err == nil {
log.Info("SELF UPDATE OK. out =", out)
log.Info("SELF UPDATE WORKED")
// me.current.SetGoState("RELEASED")
return true
log.Info("TRYING TO SELF UPDATE HERE. cmd =", docmd)
result = me.release.guireleaser.Status.Run(docmd)
}
if result.Error != nil {
log.Info("SELF UPDATE FAILED. error =", result.Error)
log.Info("SELF UPDATE FAILED. exit =", result.Exit)
log.Info("SELF UPDATE FAILED. out =", result.Stdout)
log.Info("SELF UPDATE FAILED")
return false
}
if result.Exit != 0 {
log.Info("SELF UPDATE FAILED. error =", result.Error)
log.Info("SELF UPDATE FAILED. exit =", result.Exit)
log.Info("SELF UPDATE FAILED. out =", result.Stdout)
log.Info("SELF UPDATE FAILED")
return false
}
log.Info("SELF UPDATE OK. out =", result.Stdout)
log.Info("SELF UPDATE WORKED")
return true
}

View File

@ -178,7 +178,7 @@ func createReleaseBox(box *gui.Node) {
if repo.Status.ReadOnly() {
continue
}
repo.Status.RunCmd([]string{"rm", "-f", "go.mod", "go.sum"})
repo.Status.Run([]string{"rm", "-f", "go.mod", "go.sum"})
}
me.Enable()
})
@ -191,7 +191,7 @@ func createReleaseBox(box *gui.Node) {
continue
}
log.Warn("running git reset --hard", repo.Name())
repo.Status.RunCmd([]string{"git", "reset", "--hard"})
repo.Status.Run([]string{"git", "reset", "--hard"})
}
me.Enable()
})