507 lines
13 KiB
Go
507 lines
13 KiB
Go
// This is a simple example
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
|
|
"go.wit.com/gui"
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/lib/gadgets"
|
|
"go.wit.com/lib/gui/repostatus"
|
|
)
|
|
|
|
var release releaseStruct
|
|
|
|
type releaseStruct struct {
|
|
current *repo
|
|
|
|
// win *gadgets.BasicWindow
|
|
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
|
|
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
|
|
}
|
|
|
|
func (w *autoType) Disable() {
|
|
w.mainWindow.Disable()
|
|
}
|
|
|
|
func (w *autoType) Enable() {
|
|
w.mainWindow.Enable()
|
|
}
|
|
|
|
func createReleaseBox(box *gui.Node) {
|
|
release.versionS = "0.17.0"
|
|
release.reasonS = "gocui"
|
|
partS := strings.Split(release.versionS, ".")
|
|
|
|
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()
|
|
if findNextDirty() {
|
|
log.Info("findNextDirty() found a repo")
|
|
me.Enable()
|
|
return
|
|
}
|
|
me.Enable()
|
|
})
|
|
release.grid.NewButton("next repo", func() {
|
|
buttonDisable()
|
|
defer buttonEnable()
|
|
|
|
// allrepos map[string]*repo
|
|
|
|
keys := make([]string, 0, len(me.allrepos))
|
|
for key := range me.allrepos {
|
|
keys = append(keys, key)
|
|
}
|
|
sort.Strings(keys)
|
|
|
|
for _, path := range keys {
|
|
repo := me.allrepos[path]
|
|
// mt.Printf("%s: %s\n", key, myMap[key])
|
|
|
|
//// for _, repo := range me.allrepos {
|
|
// goSumS := repo.getGoSumStatus()
|
|
// dirtyS := repo.dirtyLabel.String()
|
|
|
|
if repo.status.ReadOnly() {
|
|
log.Info("skipping repo:", path, repo.String())
|
|
} else {
|
|
log.Info("searching on repo:", path, repo.String())
|
|
tmp := repo.status.GetGoDeps()
|
|
for path, version := range tmp {
|
|
r, ok := me.allrepos[path]
|
|
if ok {
|
|
log.Info("\tfound path", path, r, version)
|
|
} else {
|
|
log.Info("\tdid not find path", path, r, version)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return
|
|
if findNextRepo() {
|
|
log.Info("findNextRepo() found a repo")
|
|
return
|
|
}
|
|
if findDirty2() {
|
|
log.Info("findDirty2() found a repo")
|
|
return
|
|
}
|
|
})
|
|
|
|
release.openrepo = release.grid.NewButton("open repo", func() {
|
|
if release.current == nil {
|
|
log.Info("find the next repo first")
|
|
return
|
|
}
|
|
// make sure read only is set
|
|
if release.current.status.ReadOnly() {
|
|
release.readOnly.SetValue("true")
|
|
} else {
|
|
release.readOnly.SetValue("false")
|
|
}
|
|
|
|
// do a new scan
|
|
release.current.newScan()
|
|
|
|
// only continue if the go.sum & go.mod files are clean
|
|
if ok, missing := release.current.status.CheckGoSum(); ok {
|
|
log.Info("repo has go.sum requirements that are clean")
|
|
release.status.SetValue("CLEAN")
|
|
release.current.setGoSumStatus("CLEAN")
|
|
} else {
|
|
log.Info("BAD repo has go.sum requirements that are screwed up. missing:", missing)
|
|
release.status.SetValue("BAD")
|
|
release.current.setGoSumStatus("BAD")
|
|
return
|
|
}
|
|
|
|
if release.current.dirtyLabel.String() == "PERFECT" {
|
|
log.Info("REPO IS STILL DIRTY")
|
|
return
|
|
}
|
|
|
|
// open the status window to commit the release
|
|
release.current.status.Toggle()
|
|
release.current.status.SetVersion(partS[0], partS[1], partS[2], release.reason.String())
|
|
release.current.status.Update()
|
|
})
|
|
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.version.SetText(release.versionS)
|
|
|
|
release.reason = gadgets.NewBasicEntry(release.grid, "release reason")
|
|
release.reason.SetText(release.reasonS)
|
|
|
|
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)
|
|
|
|
release.grid.NewButton("Check Ready", func() {
|
|
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.sendVersionB = release.grid.NewButton("send version", func() {
|
|
log.Info("set version()")
|
|
release.current.status.SetVersion(partS[0], partS[1], partS[2], release.reason.String())
|
|
})
|
|
|
|
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.checkDirtyB = release.grid.NewButton("checkDirty()", func() {
|
|
buttonDisable()
|
|
if release.current.checkDirty() {
|
|
log.Info("repo is dirty")
|
|
} else {
|
|
log.Info("repo is not dirty")
|
|
}
|
|
buttonEnable()
|
|
})
|
|
|
|
release.checkSafeB = release.grid.NewButton("checkSafeGoSumRemake()", func() {
|
|
buttonDisable()
|
|
release.current.checkSafeGoSumRemake()
|
|
buttonEnable()
|
|
})
|
|
release.checkGoSumB = release.grid.NewButton("CheckGoSum()", func() {
|
|
buttonDisable()
|
|
tmp := release.current.String()
|
|
log.Info("Run CheckGoSum on repo:", tmp)
|
|
if ok, missing := release.current.status.CheckGoSum(); ok {
|
|
log.Info("repo has go.sum requirements that are clean")
|
|
release.current.setGoSumStatus("CLEAN")
|
|
} else {
|
|
if missing == "" {
|
|
log.Info("BAD VERSION repo has go.sum requirements that are screwed up.", tmp)
|
|
if release.current.getGoSumStatus() == "BAD" {
|
|
release.current.setGoSumStatus("BAD VERSION")
|
|
}
|
|
if release.current.getGoSumStatus() == "CLEAN" {
|
|
release.current.setGoSumStatus("BAD VERSION")
|
|
}
|
|
} else {
|
|
log.Info("BAD VERSION repo has go.sum requirements that are screwed up.", tmp)
|
|
log.Info("BAD VERSION need to addRepo() the missing repo", missing)
|
|
if repostatus.VerifyLocalGoRepo(missing) {
|
|
log.Info("BAD VERSION local directory exists", missing)
|
|
addRepo(reposgrid, missing, "master", "master", "master")
|
|
} else {
|
|
log.Info("BAD VERSION local directory does not exist", missing)
|
|
log.Info("START download of:", missing)
|
|
os.Setenv("GO111MODULE", "off")
|
|
err, output := release.current.status.RunCmd([]string{"go", "get", "-v", "-u", missing})
|
|
log.Warn(output)
|
|
log.Info("END download of:", missing)
|
|
if err == nil {
|
|
log.Warn("go get worked. recheck go.sum")
|
|
} else {
|
|
log.Warn("go get failed")
|
|
}
|
|
}
|
|
// addRepo(reposgrid, missing, "master", "master", "master")
|
|
}
|
|
}
|
|
buttonEnable()
|
|
})
|
|
release.grid.NewButton("CheckPrimativeGoMod()", func() {
|
|
tmp := release.current.String()
|
|
log.Info("Run CheckGoSum on repo:", tmp)
|
|
if release.current.status.CheckPrimativeGoMod() {
|
|
log.Info("repo has PRIMATIVE go.mod")
|
|
} else {
|
|
log.Info("repo go.mod requies checking for a go.sum")
|
|
}
|
|
|
|
})
|
|
release.grid.NewButton("reset with scanGoSum()", func() {
|
|
buttonDisable()
|
|
// do an initial scan of all the repos
|
|
scanGoSum()
|
|
buttonEnable()
|
|
})
|
|
release.makeRedomodB = release.grid.NewButton("make redomod", func() {
|
|
buttonDisable()
|
|
release.current.status.MakeRedomod()
|
|
buttonEnable()
|
|
})
|
|
release.goGetB = release.grid.NewButton("go get -v -u .", func() {
|
|
buttonDisable()
|
|
err, output := release.current.status.RunCmd([]string{"go", "get", "-v", "-u", "."})
|
|
log.Warn(output)
|
|
if err == nil {
|
|
log.Warn("go get worked. recheck go.sum")
|
|
} else {
|
|
log.Warn("go get failed")
|
|
}
|
|
buttonEnable()
|
|
})
|
|
release.goGetB = release.grid.NewButton("SetMainWorkingName(guimaster)", func() {
|
|
buttonDisable()
|
|
release.current.status.SetMainWorkingName("guimaster")
|
|
buttonEnable()
|
|
})
|
|
}
|
|
|
|
func buttonDisable() {
|
|
me.Disable()
|
|
}
|
|
|
|
func buttonEnable() {
|
|
me.Enable()
|
|
}
|
|
|
|
func findDirty2() bool {
|
|
log.Info("findDirty2() START")
|
|
for _, repo := range me.allrepos {
|
|
goSumS := repo.getGoSumStatus()
|
|
dirtyS := repo.dirtyLabel.String()
|
|
|
|
if goSumS == "IGNORE" {
|
|
continue
|
|
}
|
|
|
|
if goSumS == "DIRTY 2" {
|
|
log.Info("repo DIRTY 2", repo.String(), goSumS, dirtyS)
|
|
if setCurrentRepo(repo, "dirty 2", "check manually I guess") {
|
|
return true
|
|
}
|
|
return true
|
|
} else {
|
|
log.Info("repo not DIRTY 2", repo.String(), goSumS, dirtyS)
|
|
}
|
|
}
|
|
log.Info("findDirty2() END")
|
|
return false
|
|
}
|
|
|
|
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.openrepo.Enable()
|
|
|
|
/*
|
|
if newcur.status.ReadOnly() {
|
|
release.readOnly.SetValue("true ro")
|
|
} else {
|
|
release.readOnly.SetValue("false ro")
|
|
}
|
|
*/
|
|
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") {
|
|
if CheckReady() {
|
|
release.current.setGoSumStatus("READY")
|
|
} else {
|
|
release.current.setGoSumStatus("NOT READY")
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func findNextDirty() bool {
|
|
for _, repo := range me.allrepos {
|
|
goSumS := repo.getGoSumStatus()
|
|
dirtyS := repo.dirtyLabel.String()
|
|
|
|
log.Info("findNextDirty()", repo.String(), goSumS, dirtyS)
|
|
if goSumS == "PRIMATIVE" {
|
|
if dirtyS != "PERFECT" {
|
|
if setCurrentRepo(repo, "primative not committed", "release new version") {
|
|
return true
|
|
}
|
|
continue
|
|
}
|
|
continue
|
|
}
|
|
if goSumS == "IGNORE" {
|
|
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")
|
|
return false
|
|
}
|
|
|
|
func findNextRepo() bool {
|
|
for _, repo := range me.allrepos {
|
|
goSumS := repo.getGoSumStatus()
|
|
dirtyS := repo.dirtyLabel.String()
|
|
|
|
log.Info("findNextRepo()", repo.String(), goSumS, dirtyS)
|
|
if goSumS == "IGNORE" {
|
|
continue
|
|
}
|
|
if goSumS == "DIRTY 2" {
|
|
continue
|
|
}
|
|
if goSumS == "BAD VERSION" {
|
|
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 round 2", "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 3 repo has go.sum requirements that are screwed up. missing:", missing)
|
|
repo.setGoSumStatus("DIRTY 3")
|
|
continue
|
|
}
|
|
|
|
if setCurrentRepo(repo, "dirty", "commit changes") {
|
|
return true
|
|
}
|
|
}
|
|
if goSumS == "BAD" {
|
|
// 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 setCurrentRepo(repo, "bad", "redo go.sum") {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
log.Info("tried to findNextRepo() but not sure what to do next")
|
|
return false
|
|
}
|