diff options
| author | Jeff Carr <[email protected]> | 2024-02-14 16:09:44 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-02-14 16:09:44 -0600 |
| commit | 299624110208cda4168a2e632be3a362f95b38e9 (patch) | |
| tree | 53ab925ab9e2fe245ed709275880186bfa6548f8 /releaseBox.go | |
| parent | cd4bd5b9144b90446f9a50fadca5f653f58d7c1f (diff) | |
code reorg
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'releaseBox.go')
| -rw-r--r-- | releaseBox.go | 435 |
1 files changed, 435 insertions, 0 deletions
diff --git a/releaseBox.go b/releaseBox.go new file mode 100644 index 0000000..45f9929 --- /dev/null +++ b/releaseBox.go @@ -0,0 +1,435 @@ +// This is a simple example +package main + +import ( + "os" + "path/filepath" + + "go.wit.com/gui" + "go.wit.com/log" + + "go.wit.com/lib/gadgets" +) + +var release releaseStruct + +type releaseStruct struct { + current *repo + + box *gui.Node + group *gui.Node + grid *gui.Node + repo *gadgets.OneLiner + status *gadgets.OneLiner + readOnly *gadgets.OneLiner + notes *gadgets.OneLiner + version *gadgets.OneLiner + // versionS string + // widgetVersionS string + releaseVersionB *gui.Node + unreleaseB *gui.Node + reason *gadgets.BasicEntry + // reasonS string + + openrepo *gui.Node + + goGetB *gui.Node + checkGoSumB *gui.Node + checkDirtyB *gui.Node + makeRedomodB *gui.Node + sendVersionB *gui.Node + checkSafeB *gui.Node + whitelist map[string]*repo + + // store myself here. use myself to + // do garbage go get tests and other potential junk + guireleaser *repo +} + +func (w *autoType) Disable() { + // w.mainWindow.Disable() + release.box.Disable() + // buttonDisable() +} + +func (w *autoType) Enable() { + // w.mainWindow.Enable() + release.box.Enable() + // buttonEnable() +} + +func createReleaseBox(box *gui.Node) { + initWhitelist() + + release.box = box + release.group = release.box.NewGroup("things") + release.grid = release.group.NewGrid("buildOptions", 2, 1) + + // do an initial scan of all the repos + scanGoSum() + + release.grid.NewButton("scan for Ready", func() { + me.Disable() + scanForReady() + me.Enable() + }) + release.grid.NewButton("findNextDirty()", func() { + me.Disable() + defer me.Enable() + if findNextDirty("PRIMATIVE") { + log.Info("findNextDirty() found a repo") + return + } + if findNextDirty("") { + log.Info("findNextDirty() found a repo") + return + } + }) + + release.releaseVersionB = release.grid.NewButton("release version", func() { + buttonDisable() + if doRelease() { + buttonEnable() + log.Info("doRelease() worked") + } else { + log.Info("doRelease() failed") + } + }) + + release.openrepo = release.grid.NewButton("open repo", func() { + release.current.status.Toggle() + }) + release.openrepo.Disable() + + release.repo = gadgets.NewOneLiner(release.grid, "repo") + release.status = gadgets.NewOneLiner(release.grid, "status") + release.readOnly = gadgets.NewOneLiner(release.grid, "read-only") + release.notes = gadgets.NewOneLiner(release.grid, "notes") + + release.version = gadgets.NewOneLiner(release.grid, "version") + + release.reason = gadgets.NewBasicEntry(release.grid, "release reason") + release.reason.SetText(me.releaseReasonS) + + me.autoWorkingPwd = gadgets.NewOneLiner(release.grid, "working directory (pwd)") + me.userHomePwd = gadgets.NewOneLiner(release.grid, "user home") + me.goSrcPwd = gadgets.NewOneLiner(release.grid, "go src home") + + homeDir, err := os.UserHomeDir() + if err != nil { + log.Warn("Error getting home directory:", err) + homeDir = "/home/autotypist" + } + me.userHomePwd.SetText(homeDir) + srcDir := filepath.Join(homeDir, "go/src") + me.goSrcPwd.SetText(srcDir) + + testf := filepath.Join(srcDir, "go.wit.com/apps/guireleaser", "go.sum") + if !Exists(testf) { + log.Info("go.sum missing", testf) + panic("redo go.sum") + } + + release.grid.NewButton("Check Ready", func() { + buttonDisable() + defer buttonEnable() + goSumS := release.current.getGoSumStatus() + dirtyS := release.current.dirtyLabel.String() + lastS := release.current.status.GetLastTagVersion() + if CheckReady() { + log.Info("repo is ready", release.current.String(), goSumS, dirtyS, lastS) + return + } else { + log.Info("\trepo is not ready", release.current.String(), goSumS, dirtyS, lastS) + } + }) + + release.grid.NewButton("set ignore", func() { + tmp := release.current.getGoSumStatus() + log.Info("trying to set repo IGNORE is now =", tmp) + release.current.setGoSumStatus("IGNORE") + release.whitelist[release.current.String()] = release.current + }) + + release.checkSafeB = release.grid.NewButton("fullDoubleCheckFix()", func() { + buttonDisable() + if fullDoubleCheckFix() { + log.Info("go.sum is clean") + } else { + log.Info("repo go.sum FAILED") + return + } + buttonEnable() + }) + + release.checkGoSumB = release.grid.NewButton("CheckGoSum()", func() { + buttonDisable() + if ok, _ := release.current.status.CheckGoSum(); ok { + log.Info("repo has go.sum requirements that are clean") + // release.current.setGoSumStatus("CLEAN") + release.status.SetValue("GOOD") + release.notes.SetValue("CheckGoSum() does not seem to lie") + } + buttonEnable() + }) + + release.makeRedomodB = release.grid.NewButton("make redomod", func() { + buttonDisable() + if release.current.status.MakeRedomod() { + } else { + log.Info("This is bad. stop here") + } + buttonEnable() + }) + + release.grid.NewButton("goodCheckGoSum()", func() { + buttonDisable() + if goodCheckGoSum() { + log.Info("goodCheckGoSum() GOOD") + } else { + log.Info("goodCheckGoSum() FAILED") + } + buttonEnable() + }) + + release.grid.NewButton("release all", func() { + buttonDisable() + // rather than loop forever, at least limit this to the number of repos + // incase something, somewhere, goes wrong + for n := 0; n <= len(me.allrepos); n++ { + if doRelease() { + log.Info("doRelease() worked") + } else { + if release.status.String() == "ALL DONE?" { + log.Info("maybe ALL DONE?") + buttonEnable() + return + } + log.Info("doRelease() failed") + return + } + } + buttonEnable() + }) +} + +func fullDoubleCheckFix() bool { + release.current.status.CheckSafeGoSumRemake() + if !release.current.status.MakeRedomod() { + log.Info("go mod failed") + return false + } + if ok, _ := release.current.status.CheckGoSum(); ok { + log.Info("go.sum is clean") + } else { + log.Info("repo go.sum FAILED") + return false + } + if ok, _ := release.current.status.CheckGoSum(); ok { + log.Info("repo has go.sum requirements that are clean") + // release.current.setGoSumStatus("CLEAN") + release.status.SetValue("GOOD") + release.notes.SetValue("CheckGoSum() does not seem to lie") + return true + } + return false +} + +func goodCheckGoSum() bool { + tmp := release.current.String() + log.Info("goodCheckGoSum() START on repo:", tmp, "STATUS =", release.current.getGoSumStatus()) + + var maybe bool = true + goConfig := release.current.status.GetGoDeps() + for depname, version := range goConfig { + log.Info("Checking repo deps:", depname, version) + repo, ok := me.allrepos[depname] + if ok { + goSumS := repo.getGoSumStatus() + // ignore dependencies on whitelisted repos + // TODO: warn the user about the whitelist + if goSumS == "WHITELIST" { + continue + } + // check if the dependent repo is ReadOnly + // if so, there isn't anything we can do about + // version mis-matches + if repo.status.ReadOnly() { + continue + } + lastS := repo.status.GetLastTagVersion() + targetS := repo.targetVersion.String() + log.Info(" repo deps:", depname, version, "vs", goSumS, lastS, targetS) + if lastS != targetS { + log.Info("repo deps: FALSE lastS != targetS", lastS, targetS) + log.Info("repo deps: FALSE status.ReadOnly()", release.current.status.ReadOnly()) + log.Info("repo deps: FALSE path", release.current.String()) + maybe = false + } + } else { + log.Info(" repo deps: IGNORE", depname, version) + } + } + if maybe { + log.Info("SUCCEEDED.", release.current.String()) + log.Info("SUCCEEDED. goSumStatus.String() =", release.current.goSumStatus.String()) + log.Info("SUCCEEDED. MAYBE. try it again get go.sum requirements") + return true + } else { + log.Info("FAILED. move on") + } + return false +} + +func buttonDisable() { + me.Disable() +} + +func buttonEnable() { + me.Enable() +} + +func setCurrentRepo(newcur *repo, s string, note string) bool { + if newcur.status.ReadOnly() { + return false + } + + release.repo.SetValue(newcur.status.String()) + release.status.SetValue(s) + release.notes.SetValue(note) + release.current = newcur + release.version.SetText(release.current.targetVersion.String()) + release.releaseVersionB.SetText("release version " + release.current.targetVersion.String()) + release.unreleaseB.SetText("un-release version " + release.current.targetVersion.String()) + release.openrepo.Enable() + + return true +} + +func scanForReady() bool { + for _, repo := range me.allrepos { + goSumS := repo.getGoSumStatus() + dirtyS := repo.dirtyLabel.String() + log.Info("findNextDirty()", repo.String(), goSumS, dirtyS) + + if whitelist(repo.String()) { + log.Info("found WHITELIST", repo.String()) + repo.setGoSumStatus("WHITELIST") + continue + } + + log.Info("scan for Ready: found a repo") + if setCurrentRepo(repo, "checking ready", "notsure") { + CheckReady() + } + } + return true +} + +func findNextDirty(onlyKind string) bool { + for key := range me.allrepos { + repo := me.allrepos[key] + goSumS := repo.getGoSumStatus() + dirtyS := repo.dirtyLabel.String() + + log.Info("findNextDirty()", repo.String(), goSumS, dirtyS) + if repo.status.ReadOnly() { + log.Info("findNextDirty() skipping readonly") + continue + } + if goSumS == "PRIMATIVE" { + if setCurrentRepo(repo, "PRIMATIVE", "release new version") { + if release.version.String() == release.current.status.GetLastTagVersion() { + // everything is fine. the primative has already been released + } else { + return true + } + } + continue + } else { + if onlyKind == "PRIMATIVE" { + continue + } + } + if goSumS == "IGNORE" { + continue + } + if goSumS == "RELEASED" { + continue + } + if goSumS == "WHITELIST" { + continue + } + setCurrentRepo(repo, "REDO GOSUM", "try redoing the gosum") + newgoSumS := release.current.getGoSumStatus() + newdirtyS := release.current.dirtyLabel.String() + newlastS := release.current.status.GetLastTagVersion() + if goodCheckGoSum() { + log.Info("findNextDirty() returning true from goodCheckGoSum()", newgoSumS, newgoSumS, newdirtyS, newlastS) + return true + } else { + // continue + } + if repo.String() == "go.wit.com/log" { + log.Info("findNextDirty() FOUND LOG", repo.String(), goSumS, dirtyS) + log.Info("findNextDirty() FOUND LOG", repo.String(), goSumS, dirtyS) + log.Info("findNextDirty() FOUND LOG", repo.String(), goSumS, dirtyS) + log.Info("findNextDirty() FOUND LOG", repo.String(), goSumS, dirtyS) + log.Info("findNextDirty() FOUND LOG", repo.String(), goSumS, dirtyS) + log.Sleep(10) + return true + } + continue + if goSumS == "UNRELEASED" { + if setCurrentRepo(repo, "UNRELEASED", "manually check go.sum") { + return true + } + continue + } + if goSumS == "NOT READY" { + if setCurrentRepo(repo, "NOT READY", "manually check go.sum") { + return true + } + continue + } + if goSumS == "DIRTY 2" { + continue + } + if goSumS == "BAD DEP" { + // find out what kind of BAD DEP? + continue + } + // latestversion := repo.status.GetLastTagVersion() + if goSumS == "CLEAN" { + // if it's clean here, then check and remake the go.sum file + // then stop to commit the release version + repo.checkSafeGoSumRemake() + if repo.checkDirty() { + dirtyS = repo.dirtyLabel.String() + } + if dirtyS == "PERFECT" { + continue + } + if setCurrentRepo(repo, "clean", "check manually") { + return true + } + } + if goSumS == "DIRTY" { + if ok, missing := repo.status.CheckGoSum(); ok { + log.Info("repo has go.sum requirements that are clean") + // repo.setGoSumStatus("CLEAN") + } else { + log.Info("DIRTY 2 repo has go.sum requirements that are screwed up. missing:", missing) + repo.setGoSumStatus("DIRTY 2") + continue + } + + if setCurrentRepo(repo, "dirty", "commit changes") { + return true + } + } + } + log.Info("tried to findNextDirty() but not sure what to do next") + release.status.SetValue("ALL DONE?") + return false +} |
