guireleaser/findNext.go

224 lines
7.0 KiB
Go
Raw Normal View History

// This is a simple example
package main
import (
2025-01-20 07:58:39 -06:00
"fmt"
2025-01-30 01:15:00 -06:00
"slices"
2025-01-18 11:11:06 -06:00
"go.wit.com/log"
"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
2025-01-20 07:58:39 -06:00
func checkDeps(repo *gitpb.Repo) error {
if repo.GoDeps == nil {
return fmt.Errorf("%s has GoDeps == nil", repo.GetGoPath())
}
all := repo.GoDeps.All()
for all.Scan() {
dep := all.Next()
// log.Info(repo.GetGoPath(), dep.GoPath, dep.Version)
// check if the package in question is waiting for another package to publish
found := me.forge.FindByGoPath(dep.GoPath)
if found == nil {
return fmt.Errorf("%s has dep == nil", repo.GetGoPath(), dep.GoPath)
}
all := me.found.SortByFullPath()
for all.Scan() {
check := all.Next()
if found.GetGoPath() == check.GetGoPath() {
// this package is waiting on other packages to publish
return fmt.Errorf("%s is waiting on %s", repo.GetGoPath(), found.GetGoPath())
}
}
// found package isn't being published. is the version correct?
2025-01-20 08:14:18 -06:00
// never check this? we are done?
/*
if found.GetLastTag() == dep.Version {
// everything is normal
} else {
return fmt.Errorf("%s version mismatch on %s (%s vs %s)", repo.GetGoPath(), found.GetGoPath(), found.GetLastTag(), dep.Version)
}
*/
2025-01-20 07:58:39 -06:00
}
// everything might be cool?
2025-01-18 11:11:06 -06:00
return nil
}
// 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
2025-01-19 11:51:54 -06:00
all := me.found.SortByFullPath()
2024-12-17 18:48:45 -06:00
for all.Scan() {
check := all.Next()
2025-01-29 16:41:01 -06:00
if check.GetMasterBranchName() != check.GetCurrentBranchName() {
log.Info("YOU MUST BE ON THE MASTER BRANCH", check.GetGoPath())
continue
}
2025-01-29 16:41:01 -06:00
if check.IsDirty() {
log.Info("CAN NOT RELEASE DIRTY REPO", check.GetGoPath())
continue
2025-01-20 07:58:39 -06:00
}
if alreadyDone(check) {
2025-01-29 21:24:08 -06:00
log.Info("findNext() alreadyDone. WHY IS THIS STILL CHECKING?", check.GetGoPath())
continue
}
2025-01-29 16:41:01 -06:00
log.Info("CHECKING:", check.GetGoPath())
// _, err := check.RunVerboseOnError([]string{"go-mod-clean", "--strict"})
_, err := check.RunQuiet([]string{"go-mod-clean", "--smart"})
2025-01-20 07:58:39 -06:00
if err != nil {
2025-01-29 20:43:03 -06:00
log.Info("FAILED: findNext() go-mod-clean --smart", check.GetGoPath(), err)
2025-01-29 16:41:01 -06:00
continue
}
2025-01-29 16:41:01 -06:00
2024-12-02 10:43:48 -06:00
findCounter += 1
2024-12-18 20:08:48 -06:00
if !check.ParseGoSum() {
2025-01-29 16:41:01 -06:00
log.Info("ParseGoSum() failed", check.GetGoPath())
log.Info("ParseGoSum() failed", check.GetGoPath())
log.Info("ParseGoSum() failed", check.GetGoPath())
continue
}
2025-01-29 20:43:03 -06:00
2025-01-30 01:15:00 -06:00
/*
if err := me.forge.CleanGoDepsCheckOk(check); err != nil {
log.Info("CleanGoDepsCheckOk() failed", check.GetGoPath(), err)
log.Info("CleanGoDepsCheckOk() failed", check.GetGoPath(), err)
continue
}
*/
2025-01-29 21:24:08 -06:00
2025-01-30 01:15:00 -06:00
/*
if err := checkDeps(check); err != nil {
log.Info("CHECK DEPS FAILED", check.GetGoPath(), err)
log.Info("CHECK DEPS FAILED", check.GetGoPath(), err)
log.Info("CHECK DEPS FAILED", check.GetGoPath(), err)
continue
} else {
log.Info("Might be ok?", check.GetGoPath())
}
*/
fixGodeps(check)
/*
} else {
log.Info("SKIPPING FIX", check.GetGoPath())
log.Info("SKIPPING FIX", check.GetGoPath())
log.Info("SKIPPING FIX", check.GetGoPath())
}
*/
2025-01-29 20:43:03 -06:00
2025-01-29 21:24:08 -06:00
if err := me.forge.FinalGoDepsCheckOk(check, argv.Verbose); err != nil {
2025-01-30 01:15:00 -06:00
// if err := me.forge.FinalGoDepsCheckOk(check, false); err != nil {
2025-01-29 21:24:08 -06:00
log.Info("FinalGoDepsCheckOk() repo=", check.GetGoPath(), "err:", err)
2025-01-30 01:15:00 -06:00
log.Info("CHECKING END:", check.GetGoPath())
log.Info("")
2025-01-29 21:24:08 -06:00
continue
}
2025-01-29 21:24:08 -06:00
log.Info("GOOD TO GO ON", check.GetGoPath())
setCurrentRepo(check, "should be good to release", "pretty sure")
return true
}
if findCounter == 0 {
2025-01-30 04:43:51 -06:00
log.Info("NOTHING TO UPDATE. findCounter =", findCounter, "found len =", me.found.Len())
if me.found.Len() == 0 {
okExit("")
}
} else {
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)
2025-01-30 01:15:00 -06:00
setCurrentRepo(nil, "findNext found nothing", "crap")
me.release.status.SetText("ALL DONE?")
return false
}
2024-12-13 02:21:39 -06:00
// tries to fix the go.mod and go.sum files
func fixGodeps(check *gitpb.Repo) bool {
var good bool = true
check.GoDeps = nil
if result, err := check.RunQuiet([]string{"go-mod-clean", "--strict"}); err != nil {
2025-01-30 01:15:00 -06:00
// log.Info("fixGoDeps() runGoClean() strict failed", check.GetGoPath(), err)
// log.Info("fixGoDeps() runGoClean() strict failed", check.GetGoPath(), len(result.Stdout), len(result.Stderr))
if len(result.Stderr) > 0 {
slices.Reverse(result.Stderr)
log.Info("fixGoDeps() runGoClean() strict failed", check.GetGoPath(), result.Stderr[0])
}
if len(result.Stdout) > 0 {
slices.Reverse(result.Stdout)
log.Info("fixGoDeps() runGoClean() strict failed", check.GetGoPath(), result.Stdout[0])
}
// log.Info("fixGoDeps() runGoClean() strict failed", check.GetGoPath())
return false
}
if check.ParseGoSum() {
return true
} else {
2025-01-30 01:15:00 -06:00
log.Info("ParseGoSum() failed but go-mod-clean --strict worked", check.GetGoPath())
2024-12-13 02:21:39 -06:00
return false
}
// skip primative ones
2024-12-17 20:47:35 -06:00
if check.GetGoPrimitive() {
if check.Exists("go.sum") {
log.Info("fixGoDeps() has go.sum but says it is primitive", check.GetGoPath())
return false
}
2024-12-17 07:03:17 -06:00
log.Info("fixGoDeps() skipping primitive", check.GetGoPath())
return true
}
2025-01-19 11:51:54 -06:00
log.Printf("current repo %s go dependancy count: %d\n", check.GetGoPath(), check.GoDepsLen())
log.Printf("current repo %s go dependancy count: %d\n", check.GetGoPath(), check.GoDepsLen())
log.Printf("current repo %s go dependancy count: %d\n", check.GetGoPath(), check.GoDepsLen())
2024-12-02 05:13:17 -06:00
deps := check.GoDeps.SortByGoPath()
for deps.Scan() {
depRepo := deps.Next()
// log.Info("found dep", depRepo.GetGoPath())
2024-12-17 07:03:17 -06:00
if me.forge.Config.IsReadOnly(depRepo.GetGoPath()) {
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())
}
2024-12-17 07:03:17 -06:00
found := me.forge.FindByGoPath(depRepo.GetGoPath())
2024-12-02 05:13:17 -06:00
if found == nil {
log.Info("not found:", depRepo.GetGoPath())
continue
}
2025-01-19 11:51:54 -06:00
log.Printf("%-48s dep ver=%10s repo ver=%10s target ver=%10s\n", found.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion(), found.GetTargetVersion())
if depRepo.GetVersion() != found.GetMasterVersion() {
2025-01-19 11:51:54 -06:00
log.Printf("%-48s %10s (gitpb depRepo)\n", depRepo.GetGoPath(), depRepo.GetVersion())
log.Printf("%-48s %10s (gitpb found)\n", found.GetGoPath(), found.GetMasterVersion())
2024-12-02 05:13:17 -06:00
cmd := []string{"go", "get", depRepo.GetGoPath() + "@latest"}
2025-01-19 11:51:54 -06:00
check.RunVerbose(cmd)
}
}
return good
}
2024-12-03 18:00:42 -06:00
2024-12-17 18:48:45 -06:00
func setCurrentRepo(check *gitpb.Repo, s string, note string) bool {
me.current = check
2025-01-30 01:15:00 -06:00
if check == nil {
me.release.repo.SetText("")
me.release.version.SetText("")
me.release.releaseVersionB.SetText("nope")
me.release.version.SetText("badver")
2025-01-30 01:15:00 -06:00
} else {
me.release.repo.SetText(check.GetGoPath())
me.release.version.SetText(check.GetTargetVersion())
me.release.releaseVersionB.SetText("release version " + check.GetTargetVersion())
me.release.version.SetText(check.GetTargetVersion())
2025-01-30 01:15:00 -06:00
}
2024-12-03 18:00:42 -06:00
me.release.status.SetText(s)
me.release.notes.SetText(note)
me.release.openrepo.Enable()
return true
}