guireleaser/findNext.go

177 lines
5.2 KiB
Go
Raw Normal View History

// This is a simple example
package main
import (
2025-02-09 15:05:10 -06:00
"errors"
2025-01-20 07:58:39 -06:00
"fmt"
2025-02-12 10:35:50 -06:00
"os"
2025-02-08 19:46:39 -06:00
"path/filepath"
2025-01-18 11:11:06 -06:00
"go.wit.com/log"
"go.wit.com/lib/gui/shell"
"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-02-07 11:21:51 -06:00
log.Info("CHECKING START:", check.GetGoPath())
2025-01-29 20:43:03 -06:00
2025-02-14 20:42:16 -06:00
if me.forge.Config.IsPrivate(check.GetGoPath()) {
log.Info("GOOD TO GO ON PRIVATE REPO", check.GetGoPath())
setCurrentRepo(check, "should be good to release", "pretty sure")
return true
}
2025-02-08 19:46:39 -06:00
godepsNew, err := check.GoSumFromRepo()
if err != nil {
log.Info("CHECKING go deps from repo failed", err)
continue
}
2025-02-12 10:35:50 -06:00
if godepsNew == nil {
// don't check godepsNew, but check to make sure go mod tidy actually ran without error
2025-02-14 00:09:37 -06:00
os.Unsetenv("GO111MODULE")
2025-02-12 10:35:50 -06:00
cmd := []string{"go", "mod", "tidy"}
2025-02-14 17:58:20 -06:00
err := check.RunVerbose(cmd)
2025-02-12 10:35:50 -06:00
if err != nil {
log.Info("go mod tidy failed. this go package needs to be examined by hand as it doesn't appear to be primitive")
os.Exit(-1)
}
// if godepsNew == nil, then this go package is a primitive and there is no go.sum file
} else {
if err := testGoDepsCheckOk(godepsNew, argv.Verbose); err != nil {
log.Info("CHECKING current repo deps failed", err)
continue
2025-02-12 10:35:50 -06:00
}
2025-02-08 19:46:39 -06:00
}
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 {
printDone()
log.Info("cd lib/; make debian")
wit := me.forge.FindByGoPath("go.wit.com/apps/utils/wit-test")
if wit != nil {
log.Info("cd", wit.GetFullPath())
os.Chdir(wit.GetFullPath())
shell.Exec([]string{"ls", "-l"})
shell.Exec([]string{"echo", "make", "debian-release-force"})
}
2025-01-30 04:43:51 -06:00
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-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)
2025-02-14 00:09:37 -06:00
// me.release.openrepo.Enable()
2024-12-03 18:00:42 -06:00
return true
}
2025-02-08 19:46:39 -06:00
func testGoDepsCheckOk(godeps *gitpb.GoDeps, verbose bool) error {
2025-02-09 14:50:08 -06:00
if godeps == nil {
2025-02-09 15:05:10 -06:00
return errors.New("testGoDepsCheckOk() godeps == nil")
2025-02-09 14:50:08 -06:00
}
2025-02-08 19:46:39 -06:00
all := godeps.SortByGoPath()
for all.Scan() {
depRepo := all.Next()
fullpath := filepath.Join(me.forge.GetGoSrc(), depRepo.GetGoPath())
found := me.found.FindByFullPath(fullpath)
if found == nil {
continue
}
return fmt.Errorf("dep is being upgraded %s", depRepo.GetGoPath())
}
return nil
}