guireleaser/releaseBox.go

241 lines
6.5 KiB
Go
Raw Normal View History

// This is a simple example
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"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"
2024-02-29 21:57:13 -06:00
"go.wit.com/lib/gui/shell"
)
type releaseStruct struct {
2024-03-02 20:47:10 -06:00
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
2024-03-02 20:47:10 -06:00
reason *gadgets.BasicEntry
openrepo *gui.Node
goGetB *gui.Node
checkGoSumB *gui.Node
checkDirtyB *gui.Node
makeRedomodB *gui.Node
sendVersionB *gui.Node
checkSafeB *gui.Node
2024-02-23 09:01:58 -06:00
whitelist map[string]*repolist.RepoRow
// store myself here. use myself to
// do garbage go get tests and other potential junk
2024-02-23 09:01:58 -06:00
guireleaser *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()
2024-11-07 05:15:54 -06:00
if doRelease() {
buttonEnable()
log.Info("doRelease() worked")
} else {
log.Info("doRelease() failed")
}
})
2024-02-20 20:42:54 -06:00
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() {
me.current.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()
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")
2024-02-29 21:57:13 -06:00
if !shell.Exists(testf) {
2024-12-01 11:38:15 -06:00
pb := me.forge.Repos.FindByGoPath("go.wit.com/apps/guireleaser")
if pb != nil {
pb.RedoGoMod()
}
if !shell.Exists(testf) {
log.Info("go.sum missing", testf)
panic("redo go.sum")
}
}
group := me.release.box.NewGroup("Run on Current Repo")
grid := group.NewGrid("buildOptions", 0, 0)
2024-11-13 18:10:53 -06:00
grid.NewButton("whitelist", func() {
2024-02-29 21:57:13 -06:00
// tmp := me.current.GoState()
log.Info("trying to whitelist repo", me.current.GoPath())
2024-11-13 18:10:53 -06:00
me.current.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() {
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() {
2024-11-16 00:07:53 -06:00
loop := me.repos.View.ReposSortByName()
for loop.Scan() {
loop.Repo()
2024-11-07 05:15:54 -06:00
if doRelease() {
log.Info("doRelease() worked")
} else {
2024-11-17 06:26:25 -06:00
if os.Getenv("FindNextDone") == "true" {
log.Info("findNext says it was done")
log.Info("findNext says it was done")
log.Info("we can os.Exit here")
}
if me.release.status.String() == "ALL DONE?" {
log.Info("maybe ALL DONE?")
buttonEnable()
worked = true
2024-12-03 03:51:56 -06:00
// os.Exit(0)
}
log.Info("doRelease() failed")
worked = false
break
}
}
})
s := fmt.Sprint(duration)
log.Info("release returned", worked, "and ran for", s)
buttonEnable()
})
grid.NextRow()
2024-02-20 20:42:54 -06:00
group = me.release.box.NewGroup("experimental and potentially dangerous stuff")
grid = group.NewGrid("buildOptions", 0, 0)
2024-11-13 17:23:33 -06:00
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()
grid.NewButton("git ls-files |grep go.mod", func() {
2024-11-16 00:07:53 -06:00
loop := me.repos.View.ReposSortByName()
for loop.Scan() {
repo := loop.Repo()
log.Info("repo:", repo.Name())
if repo.Status.ReadOnly() {
continue
}
2024-11-13 18:13:20 -06:00
if repo.Status.Whitelist {
log.Warn("skipping whitelist", repo.GoPath())
continue
}
good, files := repo.Status.GitLsFiles()
if !good {
log.Warn("Something went wrong", repo.GoPath())
continue
}
for _, filename := range strings.Split(files, "\n") {
log.Info("\tfile", filename)
if filename == "go.mod" {
log.Info("Found go.mod. does version match release version?")
log.Info(repo.Status.GetLastTagVersion(), "vs", repo.Status.GetTargetVersion())
if repo.Status.GetLastTagVersion() != repo.Status.GetTargetVersion() {
log.Info(repo.Status.GetLastTagVersion(), "vs", repo.Status.GetTargetVersion())
log.Info("Found go.sum. version mismatch")
setCurrentRepo(repo, "VERY BROKEN", "rewind go.mod commit")
return
}
}
if filename == "go.sum" {
log.Info("Found go.sum. does version match release version?")
log.Info(repo.Status.GetLastTagVersion(), "vs", repo.Status.GetTargetVersion())
if repo.Status.GetLastTagVersion() != repo.Status.GetTargetVersion() {
log.Info(repo.Status.GetLastTagVersion(), "vs", repo.Status.GetTargetVersion())
log.Info("Found go.sum. version mismatch")
setCurrentRepo(repo, "VERY BROKEN", "rewind go.mod commit")
return
}
}
}
}
log.Info("All repos seem okay")
})
grid.NextRow()
}
func buttonDisable() {
me.Disable()
}
func buttonEnable() {
me.Enable()
}