287 lines
6.9 KiB
Go
287 lines
6.9 KiB
Go
// This is a simple example
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"go.wit.com/gui"
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/lib/gadgets"
|
|
"go.wit.com/lib/gui/repolist"
|
|
)
|
|
|
|
var release releaseStruct
|
|
|
|
type releaseStruct struct {
|
|
current *repolist.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]*repolist.Repo
|
|
|
|
// store myself here. use myself to
|
|
// do garbage go get tests and other potential junk
|
|
guireleaser *repolist.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("Current Repo")
|
|
release.grid = release.group.NewGrid("buildOptions", 0, 0)
|
|
|
|
// 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.grid.NextRow()
|
|
|
|
release.releaseVersionB = release.grid.NewButton("release version", func() {
|
|
buttonDisable()
|
|
if doRelease() {
|
|
buttonEnable()
|
|
log.Info("doRelease() worked")
|
|
} else {
|
|
log.Info("doRelease() failed")
|
|
}
|
|
})
|
|
release.grid.NextRow()
|
|
|
|
release.repo = gadgets.NewOneLiner(release.grid, "repo")
|
|
release.openrepo = release.grid.NewButton("Configure", func() {
|
|
release.current.Status.Toggle()
|
|
})
|
|
release.openrepo.Disable()
|
|
release.grid.NextRow()
|
|
release.status = gadgets.NewOneLiner(release.grid, "status")
|
|
release.grid.NextRow()
|
|
release.readOnly = gadgets.NewOneLiner(release.grid, "read-only")
|
|
release.grid.NextRow()
|
|
release.notes = gadgets.NewOneLiner(release.grid, "notes")
|
|
release.grid.NextRow()
|
|
|
|
release.version = gadgets.NewOneLiner(release.grid, "version")
|
|
release.grid.NextRow()
|
|
|
|
release.reason = gadgets.NewBasicEntry(release.grid, "release reason")
|
|
release.reason.SetText(me.releaseReasonS)
|
|
release.grid.NextRow()
|
|
|
|
me.autoWorkingPwd = gadgets.NewOneLiner(release.grid, "working directory (pwd)")
|
|
release.grid.NextRow()
|
|
me.userHomePwd = gadgets.NewOneLiner(release.grid, "user home")
|
|
release.grid.NextRow()
|
|
me.goSrcPwd = gadgets.NewOneLiner(release.grid, "go src home")
|
|
release.grid.NextRow()
|
|
|
|
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.GoState()
|
|
dirtyS := release.current.State()
|
|
lastS := release.current.LastTag()
|
|
if CheckReady() {
|
|
log.Info("repo is ready", release.current.Name(), goSumS, dirtyS, lastS)
|
|
return
|
|
} else {
|
|
log.Info("\trepo is not ready", release.current.Name(), goSumS, dirtyS, lastS)
|
|
}
|
|
})
|
|
|
|
release.grid.NewButton("set ignore", func() {
|
|
tmp := release.current.GoState()
|
|
log.Info("trying to set repo IGNORE is now =", tmp)
|
|
release.current.SetGoState("IGNORE")
|
|
release.whitelist[release.current.GoPath()] = release.current
|
|
})
|
|
|
|
release.checkGoSumB = release.grid.NewButton("checkValidGoSum()", func() {
|
|
buttonDisable()
|
|
checkValidGoSum(release.current)
|
|
buttonEnable()
|
|
})
|
|
release.grid.NextRow()
|
|
|
|
release.grid.NewButton("release all", func() {
|
|
var worked bool = true
|
|
buttonDisable()
|
|
// rather than loop forever, at least limit this to the number of repos
|
|
// incase something, somewhere, goes wrong
|
|
duration := repolist.TimeFunction(func() {
|
|
for n := 0; n <= len(me.repos.View.AllRepos()); n++ {
|
|
if doRelease() {
|
|
log.Info("doRelease() worked")
|
|
} else {
|
|
if release.status.String() == "ALL DONE?" {
|
|
log.Info("maybe ALL DONE?")
|
|
buttonEnable()
|
|
worked = true
|
|
break
|
|
}
|
|
log.Info("doRelease() failed")
|
|
worked = false
|
|
break
|
|
}
|
|
}
|
|
})
|
|
s := fmt.Sprint(duration)
|
|
log.Info("release returned", worked, "and ran for", s)
|
|
buttonEnable()
|
|
})
|
|
release.grid.NextRow()
|
|
}
|
|
|
|
func buttonDisable() {
|
|
me.Disable()
|
|
}
|
|
|
|
func buttonEnable() {
|
|
me.Enable()
|
|
}
|
|
|
|
func setCurrentRepo(newcur *repolist.Repo, s string, note string) bool {
|
|
if newcur.ReadOnly() {
|
|
return false
|
|
}
|
|
|
|
release.repo.SetText(newcur.GoPath())
|
|
release.status.SetText(s)
|
|
release.notes.SetText(note)
|
|
release.current = newcur
|
|
release.version.SetText(release.current.Status.GetTargetVersion())
|
|
release.releaseVersionB.SetText("release version " + release.current.Status.GetTargetVersion())
|
|
// release.unreleaseB.SetText("un-release version " + release.current.targetVersion.String())
|
|
release.openrepo.Enable()
|
|
|
|
return true
|
|
}
|
|
|
|
func scanForReady() bool {
|
|
for _, repo := range me.repos.View.AllRepos() {
|
|
goSumS := repo.GoState()
|
|
dirtyS := repo.State()
|
|
log.Info("findNextDirty()", repo.GoPath(), goSumS, dirtyS)
|
|
|
|
if whitelist(repo.GoPath()) {
|
|
log.Info("found WHITELIST", repo.GoPath())
|
|
repo.SetGoState("WHITELIST")
|
|
continue
|
|
}
|
|
|
|
log.Info("scan for Ready: found a repo")
|
|
if setCurrentRepo(repo, "checking ready", "notsure") {
|
|
CheckReady()
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// trys to figure out if there is still something to update
|
|
// todo: redo this logic as it is terrible
|
|
// rename this findNext()
|
|
func findNextDirty(onlyKind string) bool {
|
|
for _, repo := range me.repos.View.AllRepos() {
|
|
goSumS := repo.GoState()
|
|
|
|
if repo.Status.GetTargetVersion() == repo.Status.GetCurrentVersion() {
|
|
continue
|
|
}
|
|
if goSumS == "WHITELIST" {
|
|
continue
|
|
}
|
|
if goSumS == "IGNORE" {
|
|
continue
|
|
}
|
|
if repo.ReadOnly() {
|
|
log.Info("findNextDirty() skipping readonly")
|
|
continue
|
|
}
|
|
if repo.CheckDirty() {
|
|
log.Info("findNextDirty() skipping readonly")
|
|
continue
|
|
}
|
|
log.Info("findNextDirty()", repo.GoPath(), goSumS)
|
|
if repo.Status.IsPrimitive() {
|
|
if setCurrentRepo(repo, "PRIMATIVE", "release new version") {
|
|
return true
|
|
}
|
|
continue
|
|
}
|
|
if checkValidGoSum(release.current) {
|
|
setCurrentRepo(repo, "should be good to release", "pretty sure")
|
|
return true
|
|
}
|
|
}
|
|
log.Info("tried to findNextDirty() but not sure what to do next")
|
|
release.status.SetText("ALL DONE?")
|
|
return false
|
|
}
|