178 lines
4.9 KiB
Go
178 lines
4.9 KiB
Go
// This is a simple example
|
|
package main
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"go.wit.com/log"
|
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
|
)
|
|
|
|
var findCounter int
|
|
var findFix bool = false
|
|
var findOk bool = true
|
|
|
|
// 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
|
|
all := me.forge.Repos.SortByFullPath()
|
|
for all.Scan() {
|
|
check := all.Next()
|
|
|
|
if check.GetTargetVersion() == "" {
|
|
// not set to upgrade
|
|
continue
|
|
}
|
|
if check.GetLastTag() == check.GetTargetVersion() {
|
|
// log.Info("findNext() no update needed", check.GetGoPath, check.GetTargetVersion(), "vs", check.GetCurrentBranchVersion())
|
|
continue
|
|
} else {
|
|
log.Info("findNext() update needed", check.GetGoPath(), check.GetTargetVersion(), "vs", check.GetCurrentBranchVersion())
|
|
}
|
|
if me.forge.Config.IsReadOnly(check.GetGoPath()) {
|
|
log.Info("findNext() skipping readonly")
|
|
continue
|
|
}
|
|
if check.CheckDirty() {
|
|
log.Info("findNext() skipping dirty")
|
|
continue
|
|
}
|
|
if findFix {
|
|
log.Info("findFix is true. running fixGoDeps()")
|
|
if fixGodeps(check) {
|
|
log.Info("fixGoDeps() returned true")
|
|
} else {
|
|
log.Info("fixGoDeps() returned false")
|
|
}
|
|
|
|
}
|
|
findCounter += 1
|
|
if check.Exists("go.mod") {
|
|
log.Info("go.mod exists here")
|
|
} else {
|
|
log.Info("go.mod is gone here")
|
|
}
|
|
if ok, err := check.ParseGoSum(); !ok {
|
|
log.Info("ParseGoSum() failed (probably repo needs go mod tidy)", err)
|
|
log.Info("ParseGoSum() findFix =", findFix, "findCounter =", findCounter)
|
|
if check.Exists("go.mod") {
|
|
log.Info("go.mod exists here")
|
|
} else {
|
|
log.Info("go.mod is gone here")
|
|
}
|
|
continue
|
|
}
|
|
if check.Exists("go.mod") {
|
|
log.Info("go.mod exists here")
|
|
} else {
|
|
log.Info("go.mod is gone here")
|
|
}
|
|
if me.forge.FinalGoDepsCheckOk(check) {
|
|
setCurrentRepo(check, "should be good to release", "pretty sure")
|
|
if check.Exists("go.mod") {
|
|
log.Info("go.mod exists here")
|
|
} else {
|
|
log.Info("go.mod is gone here")
|
|
}
|
|
return true
|
|
}
|
|
if check.Exists("go.mod") {
|
|
log.Info("go.mod exists here")
|
|
} else {
|
|
log.Info("go.mod is gone here")
|
|
}
|
|
log.Info("findNext() got to the end. repo", check.GetGoPath(), "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
|
|
}
|
|
|
|
func runGoClean(check *gitpb.Repo) bool {
|
|
// check if the package dependancies changed, if so, re-publish
|
|
check.GoDeps = nil
|
|
|
|
cmd := []string{"go-mod-clean", "--strict"}
|
|
log.Info("Running", cmd, "in", check.GetGoPath())
|
|
result := check.Run(cmd)
|
|
if result.Error != nil {
|
|
log.Info(cmd, "failed with", result.Error, check.GetGoPath())
|
|
log.Info("STDOUT")
|
|
log.Info(strings.Join(result.Stdout, "\n"))
|
|
log.Info("STDERR")
|
|
log.Info(strings.Join(result.Stderr, "\n"))
|
|
return false
|
|
}
|
|
if result.Exit != 0 {
|
|
log.Info(cmd, "failed with", result.Exit, check.GetGoPath())
|
|
log.Info("STDOUT")
|
|
log.Info(strings.Join(result.Stdout, "\n"))
|
|
log.Info("STDERR")
|
|
log.Info(strings.Join(result.Stderr, "\n"))
|
|
return false
|
|
}
|
|
if ok, err := check.ParseGoSum(); !ok {
|
|
log.Info("ParseGoSum() failed", err)
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
// tries to fix the go.mod and go.sum files
|
|
func fixGodeps(check *gitpb.Repo) bool {
|
|
var good bool = true
|
|
if !runGoClean(check) {
|
|
return false
|
|
}
|
|
// skip primative ones
|
|
if ok, _ := check.IsPrimitive(); ok {
|
|
log.Info("fixGoDeps() skipping primitive", check.GetGoPath())
|
|
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.GetGoPath()) {
|
|
log.Info("IsReadOnly = true", depRepo.GetGoPath())
|
|
continue
|
|
} else {
|
|
// log.Info("IsReadOnly = false", depRepo.GetGoPath())
|
|
}
|
|
found := me.forge.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)
|
|
}
|
|
}
|
|
return good
|
|
}
|
|
|
|
func setCurrentRepo(check *gitpb.Repo, s string, note string) bool {
|
|
me.release.repo.SetText(check.GetGoPath())
|
|
me.release.status.SetText(s)
|
|
me.release.notes.SetText(note)
|
|
me.current = check
|
|
me.release.version.SetText(check.GetTargetVersion())
|
|
me.release.releaseVersionB.SetText("release version " + check.GetTargetVersion())
|
|
me.release.openrepo.Enable()
|
|
|
|
return true
|
|
}
|