summaryrefslogtreecommitdiff
path: root/findNext.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-20 07:58:39 -0600
committerJeff Carr <[email protected]>2025-01-20 07:58:39 -0600
commitfbc3dae556b67cd93d6f8abbdee1f0c7293318ad (patch)
tree2bedae46d02fcb4e4d9d4baa0352d1d08b743be3 /findNext.go
parent9ef08346f81bf62a36b9f4146a2b272b54b8ac72 (diff)
improving the logic
Diffstat (limited to 'findNext.go')
-rw-r--r--findNext.go129
1 files changed, 98 insertions, 31 deletions
diff --git a/findNext.go b/findNext.go
index 7b091b2..b635175 100644
--- a/findNext.go
+++ b/findNext.go
@@ -2,7 +2,10 @@
package main
import (
- "time"
+ "errors"
+ "fmt"
+ "os"
+ "path/filepath"
"go.wit.com/log"
@@ -14,21 +17,87 @@ var findCounter int
var findFix bool = false
var findOk bool = true
-func rillFixGodeps(repo *gitpb.Repo) error {
- if repo.GetTargetVersion() == "" {
- // not set to upgrade
- return nil
+func checkpkgcache(repo *gitpb.Repo) error {
+ homedir, err := os.UserHomeDir()
+ if err != nil {
+ return err
+ }
+ rver := repo.GetLastTag()
+ if rver == "" {
+ return errors.New("could not get master version")
}
- if repo.GetLastTag() == repo.GetTargetVersion() {
+ moddir := filepath.Join(homedir, "go/pkg/mod", repo.GetGoPath()+"@"+rver)
+ if shell.IsDir(moddir) {
return nil
}
+
+ getpath := repo.GetGoPath() + "@" + repo.GetLastTag()
+ _, err = me.startRepo.RunVerbose([]string{"go", "get", getpath})
+ return err
+}
+
+func rillRestore(repo *gitpb.Repo) error {
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
return nil
}
- if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
+ if me.forge.Config.IsPrivate(repo.GetGoPath()) {
return nil
}
- runGoClean(repo, "--strict")
+ if err := checkpkgcache(repo); err != nil {
+ return err
+ }
+ _, err := repo.RunVerboseOnError([]string{"go-mod-clean", "--restore"})
+ if err != nil {
+ return err
+ }
+ log.Info("go-mod-clean restore worked ", repo.GetGoPath())
+ return nil
+}
+
+func slowRestore() error {
+ all := me.forge.Repos.All()
+ for all.Scan() {
+ repo := all.Next()
+ if err := rillRestore(repo); err != nil {
+ badExit(err)
+ }
+ if repo.ParseGoSum() {
+ log.Info("go-mod-clean and parse worked", repo.GetGoPath())
+ return nil
+ }
+ }
+ return nil
+}
+
+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?
+ if found.GetLastTag() == dep.Version {
+ return fmt.Errorf("%s version mismatch on %s (%s vs %s)", repo.GetGoPath(), found.GetGoPath(), found.GetLastTag(), dep.Version)
+ }
+ }
+ // everything might be cool?
return nil
}
@@ -36,42 +105,40 @@ func rillFixGodeps(repo *gitpb.Repo) error {
// todo: redo this logic as it is terrible
// rename this findNext()
func findNext() bool {
- now := time.Now()
- me.forge.RillFuncError(rillFixGodeps)
- log.Printf("rillFixGodeps() (%d total repos) took:%s\n", me.forge.Repos.Len(), shell.FormatDuration(time.Since(now)))
-
findCounter = 0
all := me.found.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())
+ if err := checkDeps(check); err != nil {
+ log.Info("\t", check.GetGoPath(), err)
continue
} else {
- log.Info("findNext() update needed", check.GetGoPath(), check.GetTargetVersion(), "vs", check.GetCurrentBranchVersion())
+ log.Info("Might be ok?", check.GetGoPath())
}
- if me.forge.Config.IsReadOnly(check.GetGoPath()) {
- log.Info("findNext() skipping readonly")
- continue
+ if check.GetMasterBranchName() != check.GetCurrentBranchName() {
+ log.Info("YOU MUST BE ON THE MASTER BRANCHES")
+ os.Exit(-1)
}
+ _, err := check.RunVerboseOnError([]string{"go-mod-clean", "--strict"})
+ if err != nil {
+ os.Exit(-1)
+ }
+
if check.IsDirty() {
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")
- }
+ /*
+ 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.ParseGoSum() {
log.Info("ParseGoSum() failed")