guireleaser/findNext.go

186 lines
5.2 KiB
Go
Raw Normal View History

// This is a simple example
package main
import (
2024-12-16 00:19:03 -06:00
"strings"
"go.wit.com/log"
2024-12-03 18:00:42 -06:00
"go.wit.com/lib/gui/repolist"
"go.wit.com/lib/protobuf/gitpb"
)
2024-12-02 10:43:48 -06:00
var findCounter int
var findFix bool = false
2024-12-11 01:19:07 -06:00
var findOk bool = true
2024-12-02 10:43:48 -06:00
// 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 {
2024-12-02 10:43:48 -06:00
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() {
2024-12-03 18:00:42 -06:00
// 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())
}
2024-12-05 12:49:07 -06:00
if me.forge.Config.IsReadOnly(check.GoPath) {
log.Info("findNext() skipping readonly")
continue
}
if check.CheckDirty() {
log.Info("findNext() skipping dirty")
continue
}
2024-12-02 10:43:48 -06:00
if findFix {
log.Info("findFix is true. running fixGoDeps()")
if fixGodeps(check) {
log.Info("fixGoDeps() returned true")
} else {
log.Info("fixGoDeps() returned false")
}
2024-12-02 10:43:48 -06:00
}
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")
}
2024-12-02 08:45:13 -06:00
if me.forge.FinalGoDepsCheckOk(check) {
setCurrentRepo(repo, "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", 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)
2024-12-02 10:43:48 -06:00
}
log.Info("tried to findNext() but not sure what to do next counter =", findCounter, "findFix =", findFix)
me.release.status.SetText("ALL DONE?")
return false
}
2024-12-13 02:21:39 -06:00
func runGoClean(check *gitpb.Repo) bool {
2024-12-02 05:13:17 -06:00
// check if the package dependancies changed, if so, re-publish
2024-12-13 02:21:39 -06:00
check.GoDeps = nil
2024-12-16 00:19:03 -06:00
cmd := []string{"go-mod-clean", "--strict"}
2024-12-13 02:21:39 -06:00
log.Info("Running", cmd, "in", check.GoPath)
2024-12-16 00:19:03 -06:00
result := check.Run(cmd)
2024-12-12 02:05:47 -06:00
if result.Error != nil {
log.Info(cmd, "failed with", result.Error, check.GoPath)
2024-12-16 00:19:03 -06:00
log.Info("STDOUT")
log.Info(strings.Join(result.Stdout, "\n"))
log.Info("STDERR")
log.Info(strings.Join(result.Stderr, "\n"))
2024-12-12 02:05:47 -06:00
return false
}
if result.Exit != 0 {
log.Info(cmd, "failed with", result.Exit, check.GoPath)
2024-12-16 00:19:03 -06:00
log.Info("STDOUT")
log.Info(strings.Join(result.Stdout, "\n"))
log.Info("STDERR")
log.Info(strings.Join(result.Stderr, "\n"))
2024-12-12 02:05:47 -06:00
return false
}
2024-12-13 02:21:39 -06:00
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.GoPath)
return true
}
2024-12-02 05:13:17 -06:00
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())
2024-12-03 13:23:55 -06:00
if me.forge.Config.IsReadOnly(depRepo.GoPath) {
2024-12-02 05:13:17 -06:00
log.Info("IsReadOnly = true", depRepo.GetGoPath())
continue
2024-12-02 05:13:17 -06:00
} else {
// log.Info("IsReadOnly = false", depRepo.GetGoPath())
}
found := me.forge.Repos.FindByGoPath(depRepo.GetGoPath())
2024-12-02 05:13:17 -06:00
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())
2024-12-02 05:13:17 -06:00
cmd := []string{"go", "get", depRepo.GetGoPath() + "@latest"}
check.Run(cmd)
}
}
return good
}
2024-12-03 18:00:42 -06:00
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
}