241 lines
7.1 KiB
Go
241 lines
7.1 KiB
Go
// This is a simple example
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"go.wit.com/gui"
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/lib/gadgets"
|
|
"go.wit.com/lib/gui/repolist"
|
|
)
|
|
|
|
type releaseStruct struct {
|
|
box *gui.Node
|
|
group *gui.Node
|
|
grid *gui.Node
|
|
repo *gadgets.OneLiner
|
|
status *gadgets.OneLiner
|
|
readOnly *gadgets.OneLiner
|
|
notes *gadgets.OneLiner
|
|
version *gadgets.OneLiner
|
|
releaseVersionB *gui.Node
|
|
reason *gadgets.BasicEntry
|
|
|
|
openrepo *gui.Node
|
|
|
|
goGetB *gui.Node
|
|
checkGoSumB *gui.Node
|
|
checkDirtyB *gui.Node
|
|
sendVersionB *gui.Node
|
|
checkSafeB *gui.Node
|
|
whitelist map[string]*repolist.RepoRow
|
|
}
|
|
|
|
func (w *autoType) Disable() {
|
|
me.mainBox.Disable()
|
|
}
|
|
|
|
func (w *autoType) Enable() {
|
|
me.mainBox.Enable()
|
|
}
|
|
|
|
func createReleaseBox(box *gui.Node) {
|
|
me.release.box = box.NewVerticalBox("vbox")
|
|
me.release.group = me.release.box.NewGroup("Current Repo")
|
|
me.release.grid = me.release.group.NewGrid("buildOptions", 0, 0)
|
|
me.release.grid.NextRow()
|
|
|
|
me.release.releaseVersionB = me.release.grid.NewButton("release version", func() {
|
|
buttonDisable()
|
|
if doRelease() {
|
|
buttonEnable()
|
|
log.Info("doRelease() worked")
|
|
} else {
|
|
log.Info("doRelease() failed")
|
|
}
|
|
})
|
|
me.release.grid.NewButton("Find Next Releasable", func() {
|
|
me.Disable()
|
|
defer me.Enable()
|
|
if findNext() {
|
|
log.Info("findNext() found a repo")
|
|
return
|
|
}
|
|
})
|
|
me.release.grid.NextRow()
|
|
|
|
me.release.repo = gadgets.NewOneLiner(me.release.grid, "repo")
|
|
me.release.openrepo = me.release.grid.NewButton("Configure", func() {
|
|
if repov := me.repos.View.FindByPath(me.current.GetGoPath()); repov != nil {
|
|
repov.Status.Toggle()
|
|
}
|
|
})
|
|
me.release.openrepo.Disable()
|
|
me.release.grid.NextRow()
|
|
me.release.status = gadgets.NewOneLiner(me.release.grid, "status")
|
|
me.release.grid.NextRow()
|
|
me.release.readOnly = gadgets.NewOneLiner(me.release.grid, "read-only")
|
|
me.release.grid.NextRow()
|
|
me.release.notes = gadgets.NewOneLiner(me.release.grid, "notes")
|
|
me.release.grid.NextRow()
|
|
|
|
me.release.version = gadgets.NewOneLiner(me.release.grid, "version")
|
|
me.release.grid.NextRow()
|
|
|
|
me.release.reason = gadgets.NewBasicEntry(me.release.grid, "release reason")
|
|
me.release.reason.SetText(me.releaseReasonS)
|
|
me.release.grid.NextRow()
|
|
|
|
me.autoWorkingPwd = gadgets.NewOneLiner(me.release.grid, "working directory (pwd)")
|
|
me.release.grid.NextRow()
|
|
// me.userHomePwd = gadgets.NewOneLiner(me.release.grid, "user home")
|
|
// me.release.grid.NextRow()
|
|
me.goSrcPwd = gadgets.NewOneLiner(me.release.grid, "go src home")
|
|
me.release.grid.NextRow()
|
|
|
|
// me.userHomePwd.SetText(homeDir)
|
|
me.goSrcPwd.SetText(me.forge.GetGoSrc())
|
|
|
|
group := me.release.box.NewGroup("Run on Current Repo")
|
|
grid := group.NewGrid("buildOptions", 0, 0)
|
|
|
|
grid.NewButton("whitelist", func() {
|
|
// tmp := me.current.GoState()
|
|
if repov := me.repos.View.FindByPath(me.current.GetGoPath()); repov != nil {
|
|
log.Info("trying to whitelist repo", me.current.GetGoPath())
|
|
repov.Status.Whitelist = true
|
|
}
|
|
findNext()
|
|
})
|
|
|
|
grid.NextRow()
|
|
|
|
group = me.release.box.NewGroup("Process against all repos")
|
|
grid = group.NewGrid("buildOptions", 0, 0)
|
|
grid.NewButton("doRelease() all", func() {
|
|
buttonDisable()
|
|
// rather than loop forever, at least limit this to the number of repos
|
|
// incase something, somewhere, goes wrong
|
|
ok, duration := doReleaseAll()
|
|
s := fmt.Sprint(duration)
|
|
log.Info("release returned", ok, "and ran for", s, "findCounter =", findCounter)
|
|
if !findOk {
|
|
log.Info("doRelease() immediately end something went wrong last time. findOk == false")
|
|
return
|
|
}
|
|
first := findCounter
|
|
if findCounter != 0 {
|
|
log.Info("should try thsi doRelease() loop again since findCounter =", findCounter)
|
|
ok, duration := doReleaseAll()
|
|
s := fmt.Sprint(duration)
|
|
log.Info("release returned", ok, "and ran for", s, "findCounter =", findCounter)
|
|
}
|
|
if !findOk {
|
|
log.Info("doRelease() immediately end something went wrong last time. findOk == false")
|
|
return
|
|
}
|
|
second := findCounter
|
|
log.Info("doReleaseAll() first =", first, "second =", second)
|
|
if first == 0 {
|
|
log.Info("doReleaseAll() first is 0. everything is done. second is", second)
|
|
log.Info("exit() here safely")
|
|
me.forge.ConfigSave()
|
|
okExit("")
|
|
return
|
|
}
|
|
|
|
if first != second {
|
|
// try a third time
|
|
log.Info("doReleaseAll() first second do not match. findNext()")
|
|
findNext()
|
|
ok, duration := doReleaseAll()
|
|
s := fmt.Sprint(duration)
|
|
log.Info("release returned", ok, "and ran for", s, "findCounter =", findCounter)
|
|
third := findCounter
|
|
log.Info("doReleaseAll() findCounter first =", first, "second =", second, "third =", third)
|
|
if !findOk {
|
|
log.Info("doRelease() immediately end something went wrong last time. findOk == false")
|
|
return
|
|
}
|
|
if (second == 0) && (third == 0) {
|
|
log.Info("doReleaseAll() SaveConfig() here and Exit(0)")
|
|
me.forge.ConfigSave()
|
|
okExit("")
|
|
}
|
|
} else {
|
|
log.Info("doReleaseAll() first second match. something has gone terribly wrong")
|
|
log.Info("killing guireleaser is a bad idea here. it will potentially loose state")
|
|
log.Info("the only way now is to parse 'go list' or ~/go/pkg/mod/<gopath>/go.sum files")
|
|
log.Info("to determine the last known version to make sure everything is redone correctly")
|
|
log.Info("this is the worst case. the better idea is to make sure it never fails")
|
|
log.Info("and restarts correctly where it left off. That might not be possible?")
|
|
log.Info("because 'go get @foo.com/bar@latest' appears to be global and so")
|
|
log.Info("some go.sum files might be correct when some are not actually published")
|
|
log.Info("TODO: is this true or not?")
|
|
}
|
|
|
|
buttonEnable()
|
|
})
|
|
grid.NextRow()
|
|
|
|
group = me.release.box.NewGroup("experimental and potentially dangerous stuff")
|
|
grid = group.NewGrid("buildOptions", 0, 0)
|
|
|
|
me.setBranchesToMasterB = grid.NewButton("set all branches to master", func() {
|
|
me.Disable()
|
|
defer me.Enable()
|
|
if setAllBranchesToMaster() {
|
|
// if it succeeds, disable this button
|
|
me.setBranchesToMasterB.Disable()
|
|
}
|
|
})
|
|
grid.NextRow()
|
|
}
|
|
|
|
func doReleaseAll() (bool, time.Duration) {
|
|
var worked bool = true
|
|
findCounter = 0
|
|
duration := repolist.TimeFunction(func() {
|
|
loop := me.repos.View.ReposSortByName()
|
|
for loop.Scan() {
|
|
loop.Repo()
|
|
if !findOk {
|
|
log.Info("doRelease() immediately end something went wrong last time. findOk == false")
|
|
worked = false
|
|
break
|
|
}
|
|
if doRelease() {
|
|
log.Info("doRelease() worked. findCounter =", findCounter)
|
|
} else {
|
|
if os.Getenv("FindNextDone") == "true" {
|
|
log.Info("findNext says it was done. findCounter =", findCounter)
|
|
log.Info("findNext says it was done. findCounter =", findCounter)
|
|
log.Info("we can exit here")
|
|
}
|
|
if me.release.status.String() == "ALL DONE?" {
|
|
log.Info("maybe ALL DONE?. findCounter =", findCounter)
|
|
worked = true
|
|
}
|
|
log.Info("doRelease() failed. findCounter =", findCounter)
|
|
worked = false
|
|
break
|
|
}
|
|
}
|
|
})
|
|
return worked, duration
|
|
}
|
|
|
|
func buttonDisable() {
|
|
me.Disable()
|
|
me.release.box.Disable()
|
|
}
|
|
|
|
func buttonEnable() {
|
|
me.Enable()
|
|
me.release.box.Enable()
|
|
}
|