From 9f7d0343397b0245fa0ba01cf488fa4bcca3bb5c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 4 Nov 2024 08:16:42 -0600 Subject: [PATCH] compliles and does stuff Signed-off-by: Jeff Carr --- Makefile | 25 ++++++++++ argv.go | 13 ++--- doSingleRepo.go | 73 ++++++++++++++++++++++++++++ http.go | 124 ++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 124 +++++++++++++++++++++++++----------------------- scanGoSum.go | 47 ------------------ 6 files changed, 294 insertions(+), 112 deletions(-) create mode 100644 doSingleRepo.go create mode 100644 http.go delete mode 100644 scanGoSum.go diff --git a/Makefile b/Makefile index 7153cbb..5d52c4a 100644 --- a/Makefile +++ b/Makefile @@ -40,3 +40,28 @@ redomod: rm -f go.* GO111MODULE= go mod init GO111MODULE= go mod tidy + +curl-help: + curl --silent http://localhost:9419/help + +curl-setBranchesToMasterB: + curl --silent http://localhost:9419/setBranchesToMasterB + +# report on the release +curl-findNext: + curl --silent http://localhost:9419/findNext + +# report on the release +curl-list-release: + curl --silent http://localhost:9419/releaselist?readonly=true + +#curl-doSingleRepo: +# curl --silent 'http://localhost:9419/doSingleRepo?repo=go.wit.com/gui&dryrun=false' + +# only show repos that need to be merged to the master branch +curl-list-changed: + curl --silent http://localhost:9419/list?perfect=false + +# include repos that you probably can't git push commits +curl-list-include-readonly: + curl --silent http://localhost:9419/list?readonly=true diff --git a/argv.go b/argv.go index 0d7aa25..e012789 100644 --- a/argv.go +++ b/argv.go @@ -6,16 +6,17 @@ package main this enables command line options from other packages like 'gui' and 'log' */ -type args struct { - Repo string `arg:"positional" help:"go import path"` - Increment bool `arg:"--increment" help:"auto increment"` - Release bool `arg:"--release" help:"do a release an exit"` +type argv struct { + Repo string `arg:"positional" help:"go import path"` + // Increment bool `arg:"--increment" help:"auto increment"` + // Release bool `arg:"--release" help:"do a release an exit"` DryRun bool `arg:"--dry-run,env:DRYRUN" help:"don't actually do the release"` Reason string `arg:"--reason" help:"tag message"` DumpVersions bool `arg:"--dump-versions" help:"dump the versions file for go.wit.com"` + Port int `arg:"--port" default:"9419" help:"do fun stuff with curl"` } -func (a args) Description() string { +func (a argv) Description() string { return ` Example usage: guireleaser go.wit.com/apps/go-clone --increment --release --dry-run --reason "blerg" @@ -24,6 +25,6 @@ This will pull down the go sources and the repositories in the go.sum file using git clone` } -func (args) Version() string { +func (argv) Version() string { return "guireleaser " + VERSION } diff --git a/doSingleRepo.go b/doSingleRepo.go new file mode 100644 index 0000000..9262a07 --- /dev/null +++ b/doSingleRepo.go @@ -0,0 +1,73 @@ +package main + +import ( + "os" + + "go.wit.com/lib/gui/repolist" + "go.wit.com/log" +) + +func doSingleRepo(myRepoName string) { + // the repo from the command line + var myrepo *repolist.RepoRow + + // find myself. the guireleaser directory is used as a working scratchpad + // for running go commands that can mess up the go.* files + // for _, repo := range me.repos.View.AllRepos() { + myrepo = me.repos.View.FindRepoByName(myRepoName) + + me.mainWindow.Disable() + defer me.mainWindow.Enable() + if myrepo == nil { + log.Info("could not find", myargs.Repo) + + } + log.Info("only going to do repo:", myrepo.GoPath()) + tmp := myargs.Reason + if tmp == "" { + tmp = os.Getenv("GUIRELEASE_REASON") + } + if tmp == "" { + tmp = "made by guireleaser" + } + + // increment all the versions + for _, repo := range me.repos.View.AllRepos() { + if whitelist(repo.GoPath()) { + continue + } + if repo.ReadOnly() { + continue + } + lasttag := repo.Status.LastTag() + if repo.Status.GetCurrentVersion() == lasttag { + log.Info("skipping unchanged repo", repo.Status.GoPath()) + repo.Status.SetTargetVersion(lasttag) + continue + } + repo.Status.IncrementRevisionVersion("go-clone") + } + // rescan all the repos + me.repos.View.ScanRepositories() + + myrepo.Status.MakeRedomod() + myrepo.Status.IncrementRevisionVersion(tmp) + _, err := me.repos.View.CheckValidGoSum(myrepo) + if err != nil { + log.Info("go mod tidy not ok", err) + return + } + if !checkValidGoSum(myrepo) { + log.Info("go.sum checks failed") + os.Exit(0) + } + setCurrentRepo(myrepo, "should be good to release", "pretty sure") + log.Info("DO THE RELEASE HERE") + log.Info("going to release", myrepo.GoPath(), "as version", myrepo.Status.GetTargetVersion()) + if myargs.DryRun { + log.Info("--dry-run == true") + } else { + log.Info("--dry-run == true") + // doRelease() + } +} diff --git a/http.go b/http.go new file mode 100644 index 0000000..8e356fb --- /dev/null +++ b/http.go @@ -0,0 +1,124 @@ +package main + +import ( + "fmt" + "net/http" + "os" + "strings" + + "go.wit.com/lib/gui/gowit" + "go.wit.com/log" +) + +// remove '?' part and trailing '/' +func cleanURL(url string) string { + url = "/" + strings.Trim(url, "/") + return url +} + +// send stuff to the socket and stdout +func msg(w http.ResponseWriter, s string) { + log.Info(s) + fmt.Fprintln(w, s) +} + +func okHandler(w http.ResponseWriter, r *http.Request) { + var route string + route = cleanURL(r.URL.Path) + + if route == "/help" { + msg(w, "list/ list modified repos") + msg(w, "list?readonly=true shows every repo") + msg(w, "") + msg(w, "setBranchesToMasterB maybe this sets everything to master?") + msg(w, "doSingleRepo?repo=go.wit.com/gui attempts to release gui") + msg(w, "") + msg(w, "setVersion?repo=go.wit.com/gui?target=0.2 attempts to set the target version to 0.2") + msg(w, "") + return + } + + if route == "/release" { + // simpleRelease(w, r) + return + } + + if route == "/gitpull" { + return + } + + if route == "/list" { + readonly := r.URL.Query().Get("readonly") + onlydirty := r.URL.Query().Get("onlydirty") + perfect := r.URL.Query().Get("perfect") + + me.repos.View.PrintReport(w, readonly, onlydirty, perfect) + return + } + + if route == "/findNext" { + me.Disable() + defer me.Enable() + if findNext() { + msg(w, "findNext() found a repo") + } else { + msg(w, "findNext() did not find a repo. You might be finished?") + } + msg(w, "repo: " + me.release.repo.String()) + msg(w, "name: " + me.release.version.String()) + msg(w, "notes: " + me.release.notes.String()) + msg(w, "status: " + me.release.status.String()) + return + } + + if route == "/releaselist" { + readonly := r.URL.Query().Get("readonly") + perfect := r.URL.Query().Get("perfect") + + me.repos.View.PrintReleaseReport(w, readonly, perfect) + return + } + + if route == "/goweblist" { + gowit.DumpVersions(me.repos.View) + return + } + + if route == "/setBranchesToMasterB" { + msg(w, "set all branches to master") + me.Disable() + defer me.Enable() + if setAllBranchesToMaster() { + // if it succeeds, disable this button + me.setBranchesToMasterB.Disable() + } + return + } + + if route == "/doSingleRepo" { + reponame := r.URL.Query().Get("repo") + msg(w, "doSingleRepo: "+reponame) + doSingleRepo(reponame) + } + + if route == "/quit" { + os.Exit(0) + return + } + + log.Warn("BAD URL =", route) + fmt.Fprintln(w, "BAD URL =", route) +} + +// starts and sits waiting for HTTP requests +func startHTTP() { + http.HandleFunc("/", okHandler) + + p := fmt.Sprintf(":%d", myargs.Port) + log.Println("Running on port", p) + + err := http.ListenAndServe(p, nil) + if err != nil { + log.Println("Error starting server:", err) + } +} diff --git a/main.go b/main.go index f5e4fac..4bd08ef 100644 --- a/main.go +++ b/main.go @@ -7,13 +7,12 @@ import ( "go.wit.com/dev/alexflint/arg" "go.wit.com/gui" "go.wit.com/lib/gui/gowit" - "go.wit.com/lib/gui/repolist" "go.wit.com/lib/gui/shell" "go.wit.com/log" ) var VERSION string -var myargs args +var myargs argv func main() { me = new(autoType) @@ -41,6 +40,9 @@ func main() { me.mainWindow = me.myGui.NewWindow("GUI release manager " + VERSION) me.mainBox = me.mainWindow.NewBox("bw hbox", true) + // start the http server for polling status + go startHTTP() + // sanity check of things that might be around that mess // up things later // if you have a go.work file, you must delete it @@ -99,7 +101,7 @@ func main() { me.repos.View.ScanRepositories() // the repo from the command line - var myrepo *repolist.RepoRow + // var myrepo *repolist.RepoRow // find myself. the guireleaser directory is used as a working scratchpad // for running go commands that can mess up the go.* files @@ -109,66 +111,70 @@ func main() { me.release.guireleaser = repo } } - if repo.GoPath() == myargs.Repo { - myrepo = repo - } + /* + if repo.GoPath() == myargs.Repo { + myrepo = repo + } + */ } - if myargs.Repo != "" { - me.mainWindow.Hide() - if myrepo == nil { - log.Info("could not find", myargs.Repo) + /* + if myargs.Repo != "" { + me.mainWindow.Hide() + if myrepo == nil { + log.Info("could not find", myargs.Repo) + os.Exit(0) + } + log.Info("only going to do repo:", myrepo.GoPath()) + tmp := myargs.Reason + if tmp == "" { + tmp = os.Getenv("GUIRELEASE_REASON") + } + if tmp == "" { + tmp = "made by guireleaser" + } + + // increment all the versions + for _, repo := range me.repos.View.AllRepos() { + if whitelist(repo.GoPath()) { + continue + } + if repo.ReadOnly() { + continue + } + lasttag := repo.Status.LastTag() + if repo.Status.GetCurrentVersion() == lasttag { + log.Info("skipping unchanged repo", repo.Status.GoPath()) + repo.Status.SetTargetVersion(lasttag) + continue + } + repo.Status.IncrementRevisionVersion("go-clone") + } + // rescan all the repos + me.repos.View.ScanRepositories() + + myrepo.Status.MakeRedomod() + myrepo.Status.IncrementRevisionVersion(tmp) + _, err := me.repos.View.CheckValidGoSum(myrepo) + if err != nil { + log.Info("go mod tidy not ok", err) + return + } + if !checkValidGoSum(myrepo) { + log.Info("go.sum checks failed") + os.Exit(0) + } + setCurrentRepo(myrepo, "should be good to release", "pretty sure") + log.Info("DO THE RELEASE HERE") + log.Info("going to release", myrepo.GoPath(), "as version", myrepo.Status.GetTargetVersion()) + if myargs.DryRun { + log.Info("--dry-run == true") + } else { + doRelease() + } os.Exit(0) } - log.Info("only going to do repo:", myrepo.GoPath()) - tmp := myargs.Reason - if tmp == "" { - tmp = os.Getenv("GUIRELEASE_REASON") - } - if tmp == "" { - tmp = "made by guireleaser" - } - - // increment all the versions - for _, repo := range me.repos.View.AllRepos() { - if whitelist(repo.GoPath()) { - continue - } - if repo.ReadOnly() { - continue - } - lasttag := repo.Status.LastTag() - if repo.Status.GetCurrentVersion() == lasttag { - log.Info("skipping unchanged repo", repo.Status.GoPath()) - repo.Status.SetTargetVersion(lasttag) - continue - } - repo.Status.IncrementRevisionVersion("go-clone") - } - // rescan all the repos - me.repos.View.ScanRepositories() - - myrepo.Status.MakeRedomod() - myrepo.Status.IncrementRevisionVersion(tmp) - _, err := me.repos.View.CheckValidGoSum(myrepo) - if err != nil { - log.Info("go mod tidy not ok", err) - return - } - if !checkValidGoSum(myrepo) { - log.Info("go.sum checks failed") - os.Exit(0) - } - setCurrentRepo(myrepo, "should be good to release", "pretty sure") - log.Info("DO THE RELEASE HERE") - log.Info("going to release", myrepo.GoPath(), "as version", myrepo.Status.GetTargetVersion()) - if myargs.DryRun { - log.Info("--dry-run == true") - } else { - doRelease() - } - os.Exit(0) - } + */ if me.release.guireleaser == nil { log.Info("Can not release if guireleaser was not found") diff --git a/scanGoSum.go b/scanGoSum.go deleted file mode 100644 index 51a821f..0000000 --- a/scanGoSum.go +++ /dev/null @@ -1,47 +0,0 @@ -// This is a simple example -package main - -/* -func scanGoSum() { - for _, repo := range me.repos.View.AllRepos() { - if repo.GoPath() == "go.wit.com/apps/guireleaser" { - if me.release.guireleaser == nil { - me.release.guireleaser = repo - } - } - latestversion := repo.Status.GetLastTagVersion() - if repo.GoState() == "BAD" { - continue - } - if repo.GoState() == "DIRTY" { - continue - } - if repo.Status.IsPrimitive() { - log.Info("PRIMITIVE repo:", latestversion, repo.GoPath()) - repo.SetGoState("PRIMITIVE") - continue - } - if repo.CheckDirty() { - log.Info("dirty repo:", latestversion, repo.GoPath()) - log.Info("dirty repo.getGoSumStatus =", repo.GoState()) - repo.SetGoState("DIRTY") - - // me.release.repo.SetValue(repo.status.String()) - // me.release.status.SetValue("dirty") - // me.release.notes.SetValue("You must commit your changes\nbefore you can continue") - // me.current = repo - // me.release.openrepo.Enable() - continue - } - status := repo.State() - if status == "PERFECT" { - continue - } else { - repo.NewScan() - } - - log.Info("repo:", latestversion, status, repo.GoPath()) - } - log.Info("scanGoSum() did everything, not sure what to do next") -} -*/