rewriting logic to repolist

This commit is contained in:
Jeff Carr 2024-02-20 06:53:07 -06:00
parent 28f5e15350
commit a5cd066cd2
6 changed files with 83 additions and 259 deletions

View File

@ -42,7 +42,7 @@ func CheckReady() bool {
if goSumS == "RELEASED" { if goSumS == "RELEASED" {
return true return true
} }
if goSumS == "PRIMATIVE" { if release.current.Status.IsPrimitive() {
if targetS == lastS { if targetS == lastS {
release.current.SetGoState("RELEASED") release.current.SetGoState("RELEASED")
} }

View File

@ -6,6 +6,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"go.wit.com/lib/gui/repolist"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
"go.wit.com/log" "go.wit.com/log"
) )
@ -23,36 +24,6 @@ func doRelease() bool {
log.Warn("version does not start with v.", release.version.String()) log.Warn("version does not start with v.", release.version.String())
return false return false
} }
switch release.current.GoState() {
case "PRIMATIVE":
log.Warn("can do PRIMATIVE", release.current.Name())
case "GOOD":
log.Warn("GOOD. lots of go.sum checks passed", release.version.String())
case "manually chosen":
log.Warn("attempting manual release", release.version.String())
/*
case "NOT READY":
log.Warn("attempting to release. TODO: recheck go.sum here", release.version.String())
log.Warn("Sleep 10")
log.Sleep(10)
case "UNRELEASED":
log.Warn("attempting to release. TODO: dig deep on go.sum here", release.version.String())
log.Warn("Sleep 10")
log.Sleep(10)
*/
default:
log.Warn("what is this?", release.version.String(), release.current.Name())
return false
}
if release.current.Status.ReadOnly() {
log.Info("sorry, it's read-only")
return true
}
if release.current.Status.CheckDirty() {
log.Info("sorry, it's still dirty")
return false
}
curName := release.current.Status.GetCurrentBranchName() curName := release.current.Status.GetCurrentBranchName()
mName := release.current.Status.GetMasterBranchName() mName := release.current.Status.GetMasterBranchName()
@ -61,11 +32,15 @@ func doRelease() bool {
return false return false
} }
if !checkValidGoSum(release.current) {
return false
}
log.Info("\ttag and push", curName, release.version.String(), me.releaseReasonS) log.Info("\ttag and push", curName, release.version.String(), me.releaseReasonS)
var all [][]string var all [][]string
all = append(all, []string{"git", "add", "-f", "go.mod"}) all = append(all, []string{"git", "add", "-f", "go.mod"})
if release.current.Status.CheckPrimativeGoMod() { if release.current.Status.IsPrimitive() {
// don't add go.sum here. TODO: check for go.sum file and fail // don't add go.sum here. TODO: check for go.sum file and fail
} else { } else {
all = append(all, []string{"git", "add", "-f", "go.sum"}) all = append(all, []string{"git", "add", "-f", "go.sum"})
@ -122,6 +97,23 @@ func doRelease() bool {
return true return true
} }
func checkValidGoSum(repo *repolist.Repo) bool {
ok, err := me.repos.View.CheckValidGoSum(repo)
if err != nil {
log.Info("go mod tidy not ok")
return false
}
if ok {
log.Info("repo has go.sum requirements that are clean")
// release.current.setGoSumStatus("CLEAN")
release.status.SetValue("GOOD")
release.notes.SetValue("CheckValidGoSum() does not seem to lie")
return true
}
release.notes.SetValue("CheckValidGoSum() failed")
return false
}
// try to figure out if there is another package to update // try to figure out if there is another package to update
func doReleaseFindNext() bool { func doReleaseFindNext() bool {
// scan for new repo // scan for new repo
@ -131,21 +123,9 @@ func doReleaseFindNext() bool {
log.Info("findNextDirty() could not find anything") log.Info("findNextDirty() could not find anything")
return false return false
} }
release.current.Status.CheckSafeGoSumRemake() if checkValidGoSum(release.current) {
if release.current.Status.MakeRedomod() {
log.Info("Redo mod ok")
} else {
log.Info("go mod tidy not ok")
return false
}
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 true
} }
release.notes.SetValue("CheckGoSum() failed")
return false return false
} }

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"os"
"strings" "strings"
"go.wit.com/gui" "go.wit.com/gui"
@ -46,20 +45,20 @@ func showHideRepos(repo *repolist.Repo) {
repo.Show() repo.Show()
} }
func globalDisplayShow() { func globalDisplayShow(repo *repolist.Repo) {
for _, repo := range me.repos.View.AllRepos() { if me.autoHideReadOnly.Checked() {
if me.autoHideReadOnly.Checked() { if repo.Status.ReadOnly() {
if repo.Status.ReadOnly() { repo.Hide()
continue return
}
} }
if me.autoHidePerfect.Checked() {
if repo.State() == "PERFECT" {
continue
}
}
repo.Show()
} }
if me.autoHidePerfect.Checked() {
if repo.State() == "PERFECT" {
repo.Hide()
return
}
}
repo.Show()
} }
func globalDisplayOptions(box *gui.Node) { func globalDisplayOptions(box *gui.Node) {
@ -76,24 +75,13 @@ func globalDisplayOptions(box *gui.Node) {
me.repos.Hide() me.repos.Hide()
} }
log.Info("showing reposwin") log.Info("showing reposwin")
// showHideRepos()
// have to run this twice for now
// scanForReady()
// scanForReady()
// findNextDirty("")
// double check the found next repo
// fullDoubleCheckFix()
}) })
hidegrid.NextRow() hidegrid.NextRow()
me.autoHideReadOnly = hidegrid.NewCheckbox("Hide read-only repos").SetChecked(true) me.autoHideReadOnly = hidegrid.NewCheckbox("Hide read-only repos").SetChecked(true)
me.autoHideReadOnly.Custom = func() { me.autoHideReadOnly.Custom = func() {
if me.autoHideReadOnly.Checked() { log.Info("registered hide function to globalDisplayShow()")
// showHideRepos() me.repos.View.RegisterHideFunction(globalDisplayShow)
} else {
globalDisplayShow()
}
} }
hidegrid.NextRow() hidegrid.NextRow()
@ -101,13 +89,6 @@ func globalDisplayOptions(box *gui.Node) {
me.autoHidePerfect.Custom = func() { me.autoHidePerfect.Custom = func() {
log.Info("registered hide function to showHideRepos()") log.Info("registered hide function to showHideRepos()")
me.repos.View.RegisterHideFunction(showHideRepos) me.repos.View.RegisterHideFunction(showHideRepos)
/*
if me.autoHidePerfect.Checked() {
showHideRepos()
} else {
globalDisplayShow()
}
*/
} }
hidegrid.NextRow() hidegrid.NextRow()
@ -155,8 +136,6 @@ func globalDisplayOptions(box *gui.Node) {
scanForReady() scanForReady()
findNextDirty("") findNextDirty("")
// double check the found next repo
fullDoubleCheckFix()
}) })
me.setBranchesToMasterB = grid.NewButton("set all branches to master", func() { me.setBranchesToMasterB = grid.NewButton("set all branches to master", func() {
@ -183,23 +162,20 @@ func globalDisplayOptions(box *gui.Node) {
}) })
var longB *gui.Node var longB *gui.Node
longB = grid.NewButton("redo go.sum", func() { longB = grid.NewButton("redo all go.sum", func() {
os.Unsetenv("GO111MODULE")
longB.Disable() longB.Disable()
me.Disable() me.Disable()
for _, repo := range me.repos.View.AllRepos() { for _, repo := range me.repos.View.AllRepos() {
if whitelist(repo.GoPath()) { if whitelist(repo.GoPath()) {
continue continue
} }
if repo.Status.ReadOnly() { ok, err := repo.Status.MakeRedomod()
continue if !ok {
} log.Info("redo go.sum failed on", repo.GoPath(), err)
if repo.Status.MakeRedomod() { me.Enable()
log.Info("redo go.sum failed on", repo.Name()) longB.Enable()
// me.Enable() longB.SetLabel("FAILED")
// longB.Enable() return
// longB.SetLabel("FAILED")
// return
} }
} }
log.Info("redo go.sum finished ok!") log.Info("redo go.sum finished ok!")

10
main.go
View File

@ -32,6 +32,11 @@ func main() {
os.Exit(0) os.Exit(0)
} }
// unset the go development ENV var to generate release files
// this is required for go mod init & tidy. Also, if the
// user drops to a shell or xterm, then they shouldn't be set there either
os.Unsetenv("GO111MODULE")
me.myGui = gui.New() me.myGui = gui.New()
me.myGui.InitEmbed(resToolkit) me.myGui.InitEmbed(resToolkit)
me.myGui.Default() me.myGui.Default()
@ -72,6 +77,9 @@ func main() {
// hopefully this is the list of all the golang packages and only the GUI golang packages // hopefully this is the list of all the golang packages and only the GUI golang packages
me.repos = makeRepoView() me.repos = makeRepoView()
// register a Show/Hide function for the repo list table
me.repos.View.RegisterHideFunction(showHideRepos)
// create the right side of the main window // create the right side of the main window
createReleaseBox(me.mainBox) createReleaseBox(me.mainBox)
@ -88,7 +96,7 @@ func main() {
// reads in the State of all the repos // reads in the State of all the repos
// TODO: should not really be necessary directly after init() // TODO: should not really be necessary directly after init()
me.repos.View.ScanRepositories() // me.repos.View.ScanRepositories()
me.Enable() me.Enable()

View File

@ -163,44 +163,9 @@ func createReleaseBox(box *gui.Node) {
release.whitelist[release.current.GoPath()] = release.current release.whitelist[release.current.GoPath()] = release.current
}) })
release.checkSafeB = release.grid.NewButton("fullDoubleCheckFix()", func() { release.checkGoSumB = release.grid.NewButton("checkValidGoSum()", func() {
buttonDisable() buttonDisable()
if fullDoubleCheckFix() { checkValidGoSum(release.current)
log.Info("go.sum is clean")
} else {
log.Info("repo go.sum FAILED")
return
}
buttonEnable()
})
release.checkGoSumB = release.grid.NewButton("CheckGoSum()", func() {
buttonDisable()
if ok, _ := release.current.Status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean")
// release.current.setGoSumStatus("CLEAN")
release.status.SetText("GOOD")
release.notes.SetText("CheckGoSum() does not seem to lie")
}
buttonEnable()
})
release.makeRedomodB = release.grid.NewButton("make redomod", func() {
buttonDisable()
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() buttonEnable()
}) })
release.grid.NextRow() release.grid.NextRow()
@ -234,77 +199,6 @@ func createReleaseBox(box *gui.Node) {
release.grid.NextRow() release.grid.NextRow()
} }
func fullDoubleCheckFix() bool {
release.current.Status.CheckSafeGoSumRemake()
if !release.current.Status.MakeRedomod() {
log.Info("go mod failed")
return false
}
if ok, _ := release.current.Status.CheckGoSum(); ok {
log.Info("go.sum is clean")
} else {
log.Info("repo go.sum FAILED")
return false
}
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 {
tmp := release.current.Name()
log.Info("goodCheckGoSum() START on repo:", tmp, "STATUS =", release.current.GoState())
var maybe bool = true
goConfig := release.current.Status.GetGoDeps()
for depname, version := range goConfig {
log.Info("Starting repo deps:", depname, version)
repo := me.repos.View.FindRepo(depname)
if repo == nil {
log.Info(" skipping repo == nil", depname, version)
continue
}
goSumS := repo.GoState()
// ignore dependencies on whitelisted repos
// TODO: warn the user about the whitelist
if goSumS == "WHITELIST" {
log.Info(" skipping repo == nil", depname, version)
continue
}
// check if the dependent repo is ReadOnly
// if so, there isn't anything we can do about
// version mis-matches
if repo.ReadOnly() {
log.Info(" repo deps: WHITELIST", depname, version)
continue
}
log.Info("Checking repo deps match:", depname, version)
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 {
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() { func buttonDisable() {
me.Disable() me.Disable()
} }
@ -352,45 +246,37 @@ func scanForReady() bool {
// trys to figure out if there is still something to update // trys to figure out if there is still something to update
// todo: redo this logic as it is terrible // todo: redo this logic as it is terrible
// rename this findNext()
func findNextDirty(onlyKind string) bool { func findNextDirty(onlyKind string) bool {
for _, repo := range me.repos.View.AllRepos() { for _, repo := range me.repos.View.AllRepos() {
goSumS := repo.GoState() goSumS := repo.GoState()
// dirtyS := repo.State()
log.Info("findNextDirty()", repo.GoPath(), goSumS) if repo.Status.GetTargetVersion() == repo.Status.GetCurrentVersion() {
if repo.ReadOnly() {
log.Info("findNextDirty() skipping readonly")
continue
}
if goSumS == "PRIMATIVE" {
if setCurrentRepo(repo, "PRIMATIVE", "release new version") {
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 continue
} }
if goSumS == "WHITELIST" { if goSumS == "WHITELIST" {
continue continue
} }
setCurrentRepo(repo, "REDO GOSUM", "try redoing the gosum") if goSumS == "IGNORE" {
newgoSumS := release.current.GoState() continue
// newdirtyS := release.current.dirtyLabel.String() }
newlastS := release.current.LastTag() if repo.ReadOnly() {
if goodCheckGoSum() { log.Info("findNextDirty() skipping readonly")
log.Info("findNextDirty() returning true from goodCheckGoSum()", newgoSumS, newgoSumS, newlastS) 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 return true
} }
} }

View File

@ -2,21 +2,9 @@
package main package main
import ( import (
"go.wit.com/lib/gui/repolist"
"go.wit.com/log" "go.wit.com/log"
) )
func checkSafeGoSumRemake(r *repolist.Repo) {
if ok, bad := r.Status.CheckSafeGoSumRemake(); ok {
log.Info("checkSafeGoSumRemake() is safe to redo")
r.SetGoState("SAFE")
r.Status.MakeRedomod()
} else {
log.Info("checkSafeGoSumRemake() is not safe. problems:", bad)
r.SetGoState("BAD DEP")
}
}
func scanGoSum() { func scanGoSum() {
for _, repo := range me.repos.View.AllRepos() { for _, repo := range me.repos.View.AllRepos() {
if repo.GoPath() == "go.wit.com/apps/guireleaser" { if repo.GoPath() == "go.wit.com/apps/guireleaser" {
@ -31,9 +19,9 @@ func scanGoSum() {
if repo.GoState() == "DIRTY" { if repo.GoState() == "DIRTY" {
continue continue
} }
if repo.Status.CheckPrimativeGoMod() { if repo.Status.IsPrimitive() {
log.Info("PRIMATIVE repo:", latestversion, repo.GoPath()) log.Info("PRIMITIVE repo:", latestversion, repo.GoPath())
repo.SetGoState("PRIMATIVE") repo.SetGoState("PRIMITIVE")
continue continue
} }
if repo.CheckDirty() { if repo.CheckDirty() {
@ -48,20 +36,6 @@ func scanGoSum() {
// release.openrepo.Enable() // release.openrepo.Enable()
continue continue
} }
if ok, missing := repo.Status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean")
repo.SetGoState("CLEAN")
} else {
log.Info("repo has go.sum requirements that are screwed up. missing:", missing)
repo.SetGoState("BAD")
// release.repo.SetValue(repo.status.String())
// release.status.SetValue("bad")
// release.notes.SetValue("the go.sum file is wrong")
// release.current = repo
// release.openrepo.Enable()
continue
}
status := repo.State() status := repo.State()
if status == "PERFECT" { if status == "PERFECT" {
continue continue