145 lines
4.3 KiB
Go
145 lines
4.3 KiB
Go
// This is a simple example
|
|
package main
|
|
|
|
import (
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/lib/gui/repolist"
|
|
"go.wit.com/lib/protobuf/gitpb"
|
|
)
|
|
|
|
var findCounter int
|
|
var findFix bool = false
|
|
|
|
// trys to figure out if there is still something to update
|
|
// todo: redo this logic as it is terrible
|
|
// rename this findNext()
|
|
func findNext() bool {
|
|
findCounter = 0
|
|
loop := me.repos.View.ReposSortByName()
|
|
for loop.Scan() {
|
|
repo := loop.Repo()
|
|
|
|
check := me.forge.Repos.FindByGoPath(repo.GoPath())
|
|
if check == nil {
|
|
log.Info("boo, you didn't git clone", repo.GoPath())
|
|
return false
|
|
}
|
|
if check.GetTargetVersion() == check.GetCurrentBranchVersion() {
|
|
// log.Info("findNext() no update needed", check.GoPath, check.GetTargetVersion(), "vs", check.GetCurrentBranchVersion())
|
|
continue
|
|
} else {
|
|
log.Info("findNext() update needed", check.GoPath, check.GetTargetVersion(), "vs", check.GetCurrentBranchVersion())
|
|
}
|
|
if me.forge.IsReadOnly(check) {
|
|
log.Info("findNext() skipping readonly")
|
|
continue
|
|
}
|
|
if check.CheckDirty() {
|
|
log.Info("findNext() skipping dirty")
|
|
continue
|
|
}
|
|
log.Info("findNext()", repo.GoPath(), "is not a primative repo")
|
|
if findFix {
|
|
log.Info("findFix is true. running fixGoDeps()")
|
|
fixGodeps(check)
|
|
}
|
|
findCounter += 1
|
|
if ok, err := check.ParseGoSum(); !ok {
|
|
log.Info("ParseGoSum() failed (probably repo needs go mod tidy)", err)
|
|
log.Info("ParseGoSum() findFix =", findFix, "findCounter =", findCounter)
|
|
continue
|
|
}
|
|
if me.forge.FinalGoDepsCheckOk(check) {
|
|
setCurrentRepo(repo, "should be good to release", "pretty sure")
|
|
return true
|
|
}
|
|
log.Info("findNext() got to the end. repo", repo.GoPath(), "did not work. trying to find a new one now")
|
|
}
|
|
if findCounter == 0 {
|
|
log.Info("NOTHING TO UPDATE. findCounter =", findCounter)
|
|
} else {
|
|
findFix = true
|
|
log.Info("me.current is nil findCounter =", findCounter, "so set findFix =", findFix)
|
|
}
|
|
log.Info("tried to findNext() but not sure what to do next counter =", findCounter, "findFix =", findFix)
|
|
me.release.status.SetText("ALL DONE?")
|
|
return false
|
|
}
|
|
|
|
// tries to fix the go.mod and go.sum files
|
|
func fixGodeps(check *gitpb.Repo) bool {
|
|
var good bool = true
|
|
// check if the package dependancies changed, if so, re-publish
|
|
// skip primative ones
|
|
if check.GetGoPrimitive() {
|
|
log.Info("fixGoDeps() skipping primitive", check.GoPath)
|
|
return true
|
|
}
|
|
ok, err := check.RedoGoMod()
|
|
if err != nil {
|
|
log.Info("fixGoDeps() RedoGoMod() error", err)
|
|
return false
|
|
}
|
|
if !ok {
|
|
log.Info("gitpb.RedoGoMod() returned false", check.GetGoPath())
|
|
return false
|
|
}
|
|
if check.GoDeps == nil {
|
|
cmd := []string{"go", "mod", "edit", "-go=1.20"}
|
|
check.Run(cmd)
|
|
return true
|
|
}
|
|
log.Printf("current repo %s go dependancy count: %d", check.GetGoPath(), check.GoDepsLen())
|
|
deps := check.GoDeps.SortByGoPath()
|
|
for deps.Scan() {
|
|
depRepo := deps.Next()
|
|
// log.Info("found dep", depRepo.GetGoPath())
|
|
if me.forge.Config.IsReadOnly(depRepo.GoPath) {
|
|
log.Info("IsReadOnly = true", depRepo.GetGoPath())
|
|
continue
|
|
} else {
|
|
// log.Info("IsReadOnly = false", depRepo.GetGoPath())
|
|
}
|
|
found := me.forge.Repos.FindByGoPath(depRepo.GetGoPath())
|
|
if found == nil {
|
|
log.Info("not found:", depRepo.GetGoPath())
|
|
continue
|
|
}
|
|
if depRepo.GetVersion() != found.GetMasterVersion() {
|
|
log.Printf("%-48s %10s (gitpb depRepo)", depRepo.GetGoPath(), depRepo.GetVersion())
|
|
log.Printf("%-48s %10s (gitpb found)", found.GetGoPath(), found.GetMasterVersion())
|
|
cmd := []string{"go", "get", depRepo.GetGoPath() + "@latest"}
|
|
check.Run(cmd)
|
|
}
|
|
}
|
|
cmd := []string{"go", "mod", "tidy"}
|
|
check.Run(cmd)
|
|
cmd = []string{"go", "mod", "edit", "-go=1.20"}
|
|
check.Run(cmd)
|
|
check.GoDeps = nil
|
|
if ok, err := check.ParseGoSum(); !ok {
|
|
log.Info("ParseGoSum() failed", err)
|
|
return false
|
|
}
|
|
return good
|
|
}
|
|
|
|
func setCurrentRepo(repo *repolist.RepoRow, s string, note string) bool {
|
|
check := me.forge.Repos.FindByGoPath(repo.GoPath())
|
|
if check == nil {
|
|
log.Info("boo, you didn't git clone", repo.GoPath())
|
|
return false
|
|
}
|
|
|
|
me.release.repo.SetText(check.GoPath)
|
|
me.release.status.SetText(s)
|
|
me.release.notes.SetText(note)
|
|
me.current = repo
|
|
me.release.version.SetText(check.GetTargetVersion())
|
|
me.release.releaseVersionB.SetText("release version " + check.GetTargetVersion())
|
|
me.release.openrepo.Enable()
|
|
|
|
return true
|
|
}
|