improving the logic
This commit is contained in:
parent
9ef08346f8
commit
fbc3dae556
113
findNext.go
113
findNext.go
|
@ -2,7 +2,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
|
||||||
|
@ -14,21 +17,87 @@ var findCounter int
|
||||||
var findFix bool = false
|
var findFix bool = false
|
||||||
var findOk bool = true
|
var findOk bool = true
|
||||||
|
|
||||||
func rillFixGodeps(repo *gitpb.Repo) error {
|
func checkpkgcache(repo *gitpb.Repo) error {
|
||||||
if repo.GetTargetVersion() == "" {
|
homedir, err := os.UserHomeDir()
|
||||||
// not set to upgrade
|
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
|
return nil
|
||||||
}
|
}
|
||||||
if repo.GetLastTag() == repo.GetTargetVersion() {
|
|
||||||
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()) {
|
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
|
if me.forge.Config.IsPrivate(repo.GetGoPath()) {
|
||||||
return nil
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,33 +105,30 @@ func rillFixGodeps(repo *gitpb.Repo) error {
|
||||||
// todo: redo this logic as it is terrible
|
// todo: redo this logic as it is terrible
|
||||||
// rename this findNext()
|
// rename this findNext()
|
||||||
func findNext() bool {
|
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
|
findCounter = 0
|
||||||
all := me.found.SortByFullPath()
|
all := me.found.SortByFullPath()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
check := all.Next()
|
check := all.Next()
|
||||||
|
if err := checkDeps(check); err != nil {
|
||||||
if check.GetTargetVersion() == "" {
|
log.Info("\t", check.GetGoPath(), err)
|
||||||
// not set to upgrade
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if check.GetLastTag() == check.GetTargetVersion() {
|
|
||||||
// log.Info("findNext() no update needed", check.GetGoPath, check.GetTargetVersion(), "vs", check.GetCurrentBranchVersion())
|
|
||||||
continue
|
continue
|
||||||
} else {
|
} 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()) {
|
if check.GetMasterBranchName() != check.GetCurrentBranchName() {
|
||||||
log.Info("findNext() skipping readonly")
|
log.Info("YOU MUST BE ON THE MASTER BRANCHES")
|
||||||
continue
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
_, err := check.RunVerboseOnError([]string{"go-mod-clean", "--strict"})
|
||||||
|
if err != nil {
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
if check.IsDirty() {
|
if check.IsDirty() {
|
||||||
log.Info("findNext() skipping dirty")
|
log.Info("findNext() skipping dirty")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
if findFix {
|
if findFix {
|
||||||
log.Info("findFix is true. running fixGoDeps()")
|
log.Info("findFix is true. running fixGoDeps()")
|
||||||
if fixGodeps(check) {
|
if fixGodeps(check) {
|
||||||
|
@ -72,6 +138,7 @@ func findNext() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
findCounter += 1
|
findCounter += 1
|
||||||
if !check.ParseGoSum() {
|
if !check.ParseGoSum() {
|
||||||
log.Info("ParseGoSum() failed")
|
log.Info("ParseGoSum() failed")
|
||||||
|
|
18
main.go
18
main.go
|
@ -45,24 +45,6 @@ func main() {
|
||||||
|
|
||||||
fhelp.CheckGoModCleanExit()
|
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()
|
// me.forge.ConfigPrintTable()
|
||||||
os.Setenv("REPO_WORK_PATH", me.forge.GetGoSrc())
|
os.Setenv("REPO_WORK_PATH", me.forge.GetGoSrc())
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/lib/gui/shell"
|
"go.wit.com/lib/gui/shell"
|
||||||
|
@ -16,6 +15,11 @@ func makePrepareRelease() {
|
||||||
me.release.box.Disable()
|
me.release.box.Disable()
|
||||||
defer me.Enable()
|
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
|
// run this each time something gets published successfully
|
||||||
rePrepareRelease()
|
rePrepareRelease()
|
||||||
|
|
||||||
|
@ -39,12 +43,13 @@ func forceReleaseVersion(repo *gitpb.Repo) {
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
// empty git notes
|
// empty git notes
|
||||||
if result, err := repo.RunStrictNew([]string{"go-mod-clean", "--purge"}); err != nil {
|
if _, err := repo.RunVerboseOnError([]string{"go-mod-clean", "--purge"}); err != nil {
|
||||||
log.Info("probably you don't have gomodclean")
|
// log.Info("probably you don't have gomodclean")
|
||||||
log.Info(strings.Join(result.Stdout, "\n"))
|
// log.Info(strings.Join(result.Stdout, "\n"))
|
||||||
log.Info(strings.Join(result.Stderr, "\n"))
|
// log.Info(strings.Join(result.Stderr, "\n"))
|
||||||
repo.Run([]string{"git", "notes", "remove"})
|
// repo.Run([]string{"git", "notes", "remove"})
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +57,10 @@ func forceReleaseVersion(repo *gitpb.Repo) {
|
||||||
log.Info("gomodclean probably failed here. that's ok", repo.GetGoPath())
|
log.Info("gomodclean probably failed here. that's ok", repo.GetGoPath())
|
||||||
// os.Exit(-1)
|
// os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
func rillGoModRestore(repo *gitpb.Repo) error {
|
func rillGoModRestore(repo *gitpb.Repo) error {
|
||||||
|
/*
|
||||||
if repo.GetTargetVersion() == "" {
|
if repo.GetTargetVersion() == "" {
|
||||||
// not set to upgrade
|
// not set to upgrade
|
||||||
return nil
|
return nil
|
||||||
|
@ -61,6 +68,7 @@ func rillGoModRestore(repo *gitpb.Repo) error {
|
||||||
if repo.GetLastTag() == repo.GetTargetVersion() {
|
if repo.GetLastTag() == repo.GetTargetVersion() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
|
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -76,9 +84,9 @@ func rePrepareRelease() {
|
||||||
me.forge = forgepb.Init()
|
me.forge = forgepb.Init()
|
||||||
me.found = new(gitpb.Repos)
|
me.found = new(gitpb.Repos)
|
||||||
|
|
||||||
now := time.Now()
|
// now := time.Now()
|
||||||
me.forge.RillFuncError(rillGoModRestore)
|
// me.forge.RillFuncError(rillGoModRestore)
|
||||||
log.Printf("rillFixGodeps() (%d total repos) took:%s\n", me.forge.Repos.Len(), shell.FormatDuration(time.Since(now)))
|
// log.Printf("rillFixGodeps() (%d total repos) took:%s\n", me.forge.Repos.Len(), shell.FormatDuration(time.Since(now)))
|
||||||
|
|
||||||
all := me.forge.Repos.SortByFullPath()
|
all := me.forge.Repos.SortByFullPath()
|
||||||
for all.Scan() {
|
for all.Scan() {
|
||||||
|
@ -124,7 +132,7 @@ func rePrepareRelease() {
|
||||||
|
|
||||||
// if the repo is a go binary or plugin for a new release for
|
// if the repo is a go binary or plugin for a new release for
|
||||||
// any library version change
|
// any library version change
|
||||||
if check.GetRepoType() == "binary" || check.GetRepoType() == "plugin" {
|
// if check.GetRepoType() == "binary" || check.GetRepoType() == "plugin" {
|
||||||
// check if the package dependancies changed, if so, re-publish
|
// check if the package dependancies changed, if so, re-publish
|
||||||
if me.forge.FinalGoDepsCheckOk(check, false) {
|
if me.forge.FinalGoDepsCheckOk(check, false) {
|
||||||
log.Printf("go.sum is perfect! %s\n", check.GetGoPath())
|
log.Printf("go.sum is perfect! %s\n", check.GetGoPath())
|
||||||
|
@ -133,7 +141,7 @@ func rePrepareRelease() {
|
||||||
log.Printf("dependancy checks indicate a new release is needed for %s\n", check.GetGoPath())
|
log.Printf("dependancy checks indicate a new release is needed for %s\n", check.GetGoPath())
|
||||||
forceReleaseVersion(check)
|
forceReleaseVersion(check)
|
||||||
me.found.AppendByGoPath(check)
|
me.found.AppendByGoPath(check)
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
me.forge.PrintHumanTable(me.found)
|
me.forge.PrintHumanTable(me.found)
|
||||||
|
|
Loading…
Reference in New Issue