improving the logic
This commit is contained in:
parent
9ef08346f8
commit
fbc3dae556
131
findNext.go
131
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
|
||||
}
|
||||
if repo.GetLastTag() == repo.GetTargetVersion() {
|
||||
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")
|
||||
}
|
||||
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")
|
||||
|
|
18
main.go
18
main.go
|
@ -45,24 +45,6 @@ func main() {
|
|||
|
||||
fhelp.CheckGoModCleanExit()
|
||||
|
||||
/*
|
||||
var bad bool = false
|
||||
all := me.forge.Repos.SortByFullPath()
|
||||
for all.Scan() {
|
||||
repo := all.Next()
|
||||
if repo.IsDevelBranch() {
|
||||
continue
|
||||
}
|
||||
log.Info("not on devel branch:", repo.GetCurrentBranchName(), repo.GetDevelBranchName())
|
||||
log.Info("not on devel branch:", repo.GetFullPath())
|
||||
log.Info("you can not continue if repos are not on devel branches")
|
||||
bad = true
|
||||
}
|
||||
if bad {
|
||||
os.Exit(-1)
|
||||
}
|
||||
*/
|
||||
|
||||
// me.forge.ConfigPrintTable()
|
||||
os.Setenv("REPO_WORK_PATH", me.forge.GetGoSrc())
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.wit.com/lib/gui/shell"
|
||||
|
@ -16,6 +15,11 @@ func makePrepareRelease() {
|
|||
me.release.box.Disable()
|
||||
defer me.Enable()
|
||||
|
||||
now := time.Now()
|
||||
me.forge.RillFuncError(rillRestore)
|
||||
// slowRestore()
|
||||
log.Printf("showRestore() (%d total repos) took:%s\n", me.forge.Repos.Len(), shell.FormatDuration(time.Since(now)))
|
||||
|
||||
// run this each time something gets published successfully
|
||||
rePrepareRelease()
|
||||
|
||||
|
@ -39,28 +43,32 @@ func forceReleaseVersion(repo *gitpb.Repo) {
|
|||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
// empty git notes
|
||||
if result, err := repo.RunStrictNew([]string{"go-mod-clean", "--purge"}); err != nil {
|
||||
log.Info("probably you don't have gomodclean")
|
||||
log.Info(strings.Join(result.Stdout, "\n"))
|
||||
log.Info(strings.Join(result.Stderr, "\n"))
|
||||
repo.Run([]string{"git", "notes", "remove"})
|
||||
os.Exit(-1)
|
||||
}
|
||||
/*
|
||||
// empty git notes
|
||||
if _, err := repo.RunVerboseOnError([]string{"go-mod-clean", "--purge"}); err != nil {
|
||||
// log.Info("probably you don't have gomodclean")
|
||||
// log.Info(strings.Join(result.Stdout, "\n"))
|
||||
// log.Info(strings.Join(result.Stderr, "\n"))
|
||||
// repo.Run([]string{"git", "notes", "remove"})
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
if !runGoClean(repo, "--restore") {
|
||||
log.Info("gomodclean probably failed here. that's ok", repo.GetGoPath())
|
||||
// os.Exit(-1)
|
||||
}
|
||||
if !runGoClean(repo, "--restore") {
|
||||
log.Info("gomodclean probably failed here. that's ok", repo.GetGoPath())
|
||||
// os.Exit(-1)
|
||||
}
|
||||
*/
|
||||
}
|
||||
func rillGoModRestore(repo *gitpb.Repo) error {
|
||||
if repo.GetTargetVersion() == "" {
|
||||
// not set to upgrade
|
||||
return nil
|
||||
}
|
||||
if repo.GetLastTag() == repo.GetTargetVersion() {
|
||||
return nil
|
||||
}
|
||||
/*
|
||||
if repo.GetTargetVersion() == "" {
|
||||
// not set to upgrade
|
||||
return nil
|
||||
}
|
||||
if repo.GetLastTag() == repo.GetTargetVersion() {
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
|
||||
return nil
|
||||
}
|
||||
|
@ -76,9 +84,9 @@ func rePrepareRelease() {
|
|||
me.forge = forgepb.Init()
|
||||
me.found = new(gitpb.Repos)
|
||||
|
||||
now := time.Now()
|
||||
me.forge.RillFuncError(rillGoModRestore)
|
||||
log.Printf("rillFixGodeps() (%d total repos) took:%s\n", me.forge.Repos.Len(), shell.FormatDuration(time.Since(now)))
|
||||
// now := time.Now()
|
||||
// me.forge.RillFuncError(rillGoModRestore)
|
||||
// log.Printf("rillFixGodeps() (%d total repos) took:%s\n", me.forge.Repos.Len(), shell.FormatDuration(time.Since(now)))
|
||||
|
||||
all := me.forge.Repos.SortByFullPath()
|
||||
for all.Scan() {
|
||||
|
@ -124,16 +132,16 @@ func rePrepareRelease() {
|
|||
|
||||
// if the repo is a go binary or plugin for a new release for
|
||||
// any library version change
|
||||
if check.GetRepoType() == "binary" || check.GetRepoType() == "plugin" {
|
||||
// check if the package dependancies changed, if so, re-publish
|
||||
if me.forge.FinalGoDepsCheckOk(check, false) {
|
||||
log.Printf("go.sum is perfect! %s\n", check.GetGoPath())
|
||||
continue
|
||||
}
|
||||
log.Printf("dependancy checks indicate a new release is needed for %s\n", check.GetGoPath())
|
||||
forceReleaseVersion(check)
|
||||
me.found.AppendByGoPath(check)
|
||||
// if check.GetRepoType() == "binary" || check.GetRepoType() == "plugin" {
|
||||
// check if the package dependancies changed, if so, re-publish
|
||||
if me.forge.FinalGoDepsCheckOk(check, false) {
|
||||
log.Printf("go.sum is perfect! %s\n", check.GetGoPath())
|
||||
continue
|
||||
}
|
||||
log.Printf("dependancy checks indicate a new release is needed for %s\n", check.GetGoPath())
|
||||
forceReleaseVersion(check)
|
||||
me.found.AppendByGoPath(check)
|
||||
// }
|
||||
|
||||
}
|
||||
me.forge.PrintHumanTable(me.found)
|
||||
|
|
Loading…
Reference in New Issue