guireleaser/releaseBox.go

401 lines
10 KiB
Go
Raw Normal View History

// 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"
2024-02-18 15:09:04 -06:00
"go.wit.com/lib/gui/repolist"
)
var release releaseStruct
type releaseStruct struct {
2024-02-18 15:09:04 -06:00
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
2024-02-18 15:09:04 -06:00
whitelist map[string]*repolist.Repo
// store myself here. use myself to
// do garbage go get tests and other potential junk
2024-02-18 15:09:04 -06:00
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
2024-02-19 14:40:21 -06:00
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() {
2024-02-19 19:42:14 -06:00
me.Disable()
defer me.Enable()
if findNextDirty("PRIMATIVE") {
log.Info("findNextDirty() found a repo")
return
}
if findNextDirty("") {
log.Info("findNextDirty() found a repo")
return
}
})
2024-02-19 19:42:14 -06:00
release.grid.NextRow()
release.releaseVersionB = release.grid.NewButton("release version", func() {
buttonDisable()
if doRelease() {
buttonEnable()
log.Info("doRelease() worked")
} else {
log.Info("doRelease() failed")
}
})
2024-02-19 19:42:14 -06:00
release.grid.NextRow()
2024-02-19 19:42:14 -06:00
release.repo = gadgets.NewOneLiner(release.grid, "repo")
release.openrepo = release.grid.NewButton("Configure", func() {
2024-02-18 15:09:04 -06:00
release.current.Status.Toggle()
})
release.openrepo.Disable()
2024-02-19 14:40:21 -06:00
release.grid.NextRow()
release.status = gadgets.NewOneLiner(release.grid, "status")
2024-02-19 14:40:21 -06:00
release.grid.NextRow()
release.readOnly = gadgets.NewOneLiner(release.grid, "read-only")
2024-02-19 14:40:21 -06:00
release.grid.NextRow()
release.notes = gadgets.NewOneLiner(release.grid, "notes")
2024-02-19 14:40:21 -06:00
release.grid.NextRow()
release.version = gadgets.NewOneLiner(release.grid, "version")
2024-02-19 14:40:21 -06:00
release.grid.NextRow()
release.reason = gadgets.NewBasicEntry(release.grid, "release reason")
release.reason.SetText(me.releaseReasonS)
2024-02-19 14:40:21 -06:00
release.grid.NextRow()
me.autoWorkingPwd = gadgets.NewOneLiner(release.grid, "working directory (pwd)")
2024-02-19 14:40:21 -06:00
release.grid.NextRow()
me.userHomePwd = gadgets.NewOneLiner(release.grid, "user home")
2024-02-19 14:40:21 -06:00
release.grid.NextRow()
me.goSrcPwd = gadgets.NewOneLiner(release.grid, "go src home")
2024-02-19 14:40:21 -06:00
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()
2024-02-18 15:09:04 -06:00
goSumS := release.current.GoState()
dirtyS := release.current.State()
lastS := release.current.LastTag()
if CheckReady() {
2024-02-18 15:09:04 -06:00
log.Info("repo is ready", release.current.Name(), goSumS, dirtyS, lastS)
return
} else {
2024-02-18 15:09:04 -06:00
log.Info("\trepo is not ready", release.current.Name(), goSumS, dirtyS, lastS)
}
})
release.grid.NewButton("set ignore", func() {
2024-02-18 15:09:04 -06:00
tmp := release.current.GoState()
log.Info("trying to set repo IGNORE is now =", tmp)
2024-02-18 15:09:04 -06:00
release.current.SetGoState("IGNORE")
release.whitelist[release.current.GoPath()] = 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()
2024-02-18 15:09:04 -06:00
if ok, _ := release.current.Status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean")
// release.current.setGoSumStatus("CLEAN")
2024-02-18 15:09:04 -06:00
release.status.SetText("GOOD")
release.notes.SetText("CheckGoSum() does not seem to lie")
}
buttonEnable()
})
release.makeRedomodB = release.grid.NewButton("make redomod", func() {
buttonDisable()
2024-02-18 15:09:04 -06:00
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()
})
2024-02-19 14:40:21 -06:00
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
2024-02-18 15:09:04 -06:00
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()
})
2024-02-19 14:40:21 -06:00
release.grid.NextRow()
}
func fullDoubleCheckFix() bool {
2024-02-18 15:09:04 -06:00
release.current.Status.CheckSafeGoSumRemake()
if !release.current.Status.MakeRedomod() {
log.Info("go mod failed")
return false
}
2024-02-18 15:09:04 -06:00
if ok, _ := release.current.Status.CheckGoSum(); ok {
log.Info("go.sum is clean")
} else {
log.Info("repo go.sum FAILED")
return false
}
2024-02-18 15:09:04 -06:00
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 {
2024-02-18 15:09:04 -06:00
tmp := release.current.Name()
log.Info("goodCheckGoSum() START on repo:", tmp, "STATUS =", release.current.GoState())
var maybe bool = true
2024-02-18 15:09:04 -06:00
goConfig := release.current.Status.GetGoDeps()
for depname, version := range goConfig {
2024-02-19 22:00:58 -06:00
log.Info("Starting repo deps:", depname, version)
2024-02-18 15:09:04 -06:00
repo := me.repos.View.FindRepo(depname)
2024-02-19 22:00:58 -06:00
if repo == nil {
log.Info(" skipping repo == nil", depname, version)
2024-02-18 15:09:04 -06:00
continue
}
goSumS := repo.GoState()
// ignore dependencies on whitelisted repos
// TODO: warn the user about the whitelist
if goSumS == "WHITELIST" {
2024-02-19 22:00:58 -06:00
log.Info(" skipping repo == nil", depname, version)
2024-02-18 15:09:04 -06:00
continue
}
// check if the dependent repo is ReadOnly
// if so, there isn't anything we can do about
// version mis-matches
if repo.ReadOnly() {
2024-02-19 22:00:58 -06:00
log.Info(" repo deps: WHITELIST", depname, version)
2024-02-18 15:09:04 -06:00
continue
}
2024-02-19 22:00:58 -06:00
log.Info("Checking repo deps match:", depname, version)
2024-02-18 15:09:04 -06:00
lastS := repo.LastTag()
targetS := repo.Status.GetTargetVersion()
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.ReadOnly())
log.Info("repo deps: FALSE path", release.current.GoPath())
maybe = false
}
}
if maybe {
2024-02-18 15:09:04 -06:00
log.Info("SUCCEEDED.", release.current.Name())
log.Info("SUCCEEDED. goSumStatus.String() =", release.current.GoState())
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()
}
2024-02-18 15:09:04 -06:00
func setCurrentRepo(newcur *repolist.Repo, s string, note string) bool {
if newcur.ReadOnly() {
return false
}
2024-02-18 15:09:04 -06:00
release.repo.SetText(newcur.GoPath())
release.status.SetText(s)
release.notes.SetText(note)
release.current = newcur
2024-02-18 15:09:04 -06:00
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 {
2024-02-18 15:09:04 -06:00
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())
2024-02-18 17:55:59 -06:00
repo.SetGoState("WHITELIST")
continue
}
log.Info("scan for Ready: found a repo")
if setCurrentRepo(repo, "checking ready", "notsure") {
CheckReady()
}
}
return true
}
2024-02-18 15:09:04 -06:00
// trys to figure out if there is still something to update
// todo: redo this logic as it is terrible
func findNextDirty(onlyKind string) bool {
2024-02-18 15:09:04 -06:00
for _, repo := range me.repos.View.AllRepos() {
2024-02-18 17:55:59 -06:00
goSumS := repo.GoState()
2024-02-18 15:09:04 -06:00
// dirtyS := repo.State()
2024-02-18 15:09:04 -06:00
log.Info("findNextDirty()", repo.GoPath(), goSumS)
if repo.ReadOnly() {
log.Info("findNextDirty() skipping readonly")
continue
}
if goSumS == "PRIMATIVE" {
if setCurrentRepo(repo, "PRIMATIVE", "release new version") {
2024-02-18 15:09:04 -06:00
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")
2024-02-18 15:09:04 -06:00
newgoSumS := release.current.GoState()
// newdirtyS := release.current.dirtyLabel.String()
newlastS := release.current.LastTag()
if goodCheckGoSum() {
2024-02-18 15:09:04 -06:00
log.Info("findNextDirty() returning true from goodCheckGoSum()", newgoSumS, newgoSumS, newlastS)
return true
}
}
log.Info("tried to findNextDirty() but not sure what to do next")
2024-02-18 15:09:04 -06:00
release.status.SetText("ALL DONE?")
return false
}