2024-12-01 17:36:34 -06:00
|
|
|
// This is a simple example
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2025-01-20 07:58:39 -06:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2025-01-18 11:11:06 -06:00
|
|
|
|
2024-12-01 17:36:34 -06:00
|
|
|
"go.wit.com/log"
|
|
|
|
|
2025-01-18 11:11:06 -06:00
|
|
|
"go.wit.com/lib/gui/shell"
|
2024-12-03 03:18:27 -06:00
|
|
|
"go.wit.com/lib/protobuf/gitpb"
|
2024-12-01 17:36:34 -06:00
|
|
|
)
|
|
|
|
|
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 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")
|
2025-01-18 11:31:36 -06:00
|
|
|
}
|
2025-01-20 07:58:39 -06:00
|
|
|
moddir := filepath.Join(homedir, "go/pkg/mod", repo.GetGoPath()+"@"+rver)
|
|
|
|
if shell.IsDir(moddir) {
|
2025-01-18 11:31:36 -06:00
|
|
|
return nil
|
|
|
|
}
|
2025-01-20 07:58:39 -06:00
|
|
|
|
|
|
|
getpath := repo.GetGoPath() + "@" + repo.GetLastTag()
|
|
|
|
_, err = me.startRepo.RunVerbose([]string{"go", "get", getpath})
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func rillRestore(repo *gitpb.Repo) error {
|
2025-01-18 11:31:36 -06:00
|
|
|
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
|
|
|
|
return nil
|
|
|
|
}
|
2025-01-20 07:58:39 -06:00
|
|
|
if me.forge.Config.IsPrivate(repo.GetGoPath()) {
|
2025-01-19 04:32:01 -06:00
|
|
|
return nil
|
2025-01-18 11:11:06 -06:00
|
|
|
}
|
2025-01-20 07:58:39 -06:00
|
|
|
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?
|
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
|
|
|
|
}
|
|
|
|
|
2024-12-01 17:36:34 -06:00
|
|
|
// 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-20 07:58:39 -06:00
|
|
|
if err := checkDeps(check); err != nil {
|
|
|
|
log.Info("\t", check.GetGoPath(), err)
|
2024-12-01 17:36:34 -06:00
|
|
|
continue
|
2024-12-03 15:16:41 -06:00
|
|
|
} else {
|
2025-01-20 07:58:39 -06:00
|
|
|
log.Info("Might be ok?", check.GetGoPath())
|
2024-12-01 17:36:34 -06:00
|
|
|
}
|
2025-01-20 07:58:39 -06:00
|
|
|
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)
|
2024-12-01 17:36:34 -06:00
|
|
|
}
|
2025-01-20 07:58:39 -06:00
|
|
|
|
2025-01-18 11:31:36 -06:00
|
|
|
if check.IsDirty() {
|
2024-12-01 17:36:34 -06:00
|
|
|
log.Info("findNext() skipping dirty")
|
|
|
|
continue
|
|
|
|
}
|
2025-01-20 07:58:39 -06:00
|
|
|
/*
|
|
|
|
if findFix {
|
|
|
|
log.Info("findFix is true. running fixGoDeps()")
|
|
|
|
if fixGodeps(check) {
|
|
|
|
log.Info("fixGoDeps() returned true")
|
|
|
|
} else {
|
|
|
|
log.Info("fixGoDeps() returned false")
|
|
|
|
}
|
2025-01-19 11:51:54 -06:00
|
|
|
|
2025-01-20 07:58:39 -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-19 11:51:54 -06:00
|
|
|
log.Info("ParseGoSum() failed")
|
|
|
|
log.Info("ParseGoSum() failed")
|
|
|
|
log.Info("ParseGoSum() failed")
|
2024-12-03 15:16:41 -06:00
|
|
|
continue
|
|
|
|
}
|
2025-01-17 05:30:24 -06:00
|
|
|
if me.forge.FinalGoDepsCheckOk(check, false) {
|
2024-12-17 18:48:45 -06:00
|
|
|
setCurrentRepo(check, "should be good to release", "pretty sure")
|
2024-12-01 17:36:34 -06:00
|
|
|
return true
|
2025-01-19 11:51:54 -06:00
|
|
|
} else {
|
|
|
|
log.Info("FinalGoDepsCheckOk() failed")
|
|
|
|
log.Info("FinalGoDepsCheckOk() failed")
|
|
|
|
log.Info("FinalGoDepsCheckOk() failed")
|
2024-12-01 17:36:34 -06:00
|
|
|
}
|
2024-12-17 18:48:45 -06:00
|
|
|
log.Info("findNext() got to the end. repo", check.GetGoPath(), "did not work. trying to find a new one now")
|
2024-12-01 17:36:34 -06:00
|
|
|
}
|
2024-12-03 03:18:27 -06:00
|
|
|
if findCounter == 0 {
|
|
|
|
log.Info("NOTHING TO UPDATE. findCounter =", findCounter)
|
|
|
|
} else {
|
|
|
|
findFix = true
|
|
|
|
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)
|
2024-12-01 17:36:34 -06:00
|
|
|
me.release.status.SetText("ALL DONE?")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-12-18 20:08:48 -06:00
|
|
|
func runGoClean(check *gitpb.Repo, myarg string) bool {
|
2024-12-02 05:13:17 -06:00
|
|
|
// check if the package dependancies changed, if so, re-publish
|
2024-12-13 02:21:39 -06:00
|
|
|
check.GoDeps = nil
|
|
|
|
|
2024-12-18 20:08:48 -06:00
|
|
|
cmd := []string{"go-mod-clean", myarg}
|
2025-01-19 10:48:16 -06:00
|
|
|
// log.Info("Running", cmd, "in", check.GetGoPath())
|
2024-12-16 00:19:03 -06:00
|
|
|
result := check.Run(cmd)
|
2024-12-12 02:05:47 -06:00
|
|
|
if result.Error != nil {
|
2025-01-08 04:53:45 -06:00
|
|
|
/*
|
|
|
|
log.Info(cmd, "failed with", result.Error, check.GetGoPath())
|
|
|
|
log.Info("STDOUT")
|
|
|
|
log.Info(strings.Join(result.Stdout, "\n"))
|
|
|
|
log.Info("STDERR")
|
|
|
|
log.Info(strings.Join(result.Stderr, "\n"))
|
|
|
|
*/
|
2024-12-12 02:05:47 -06:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
if result.Exit != 0 {
|
2025-01-08 04:53:45 -06:00
|
|
|
/*
|
|
|
|
log.Info(cmd, "failed with", result.Exit, check.GetGoPath())
|
|
|
|
log.Info("STDOUT")
|
|
|
|
log.Info(strings.Join(result.Stdout, "\n"))
|
|
|
|
log.Info("STDERR")
|
|
|
|
log.Info(strings.Join(result.Stderr, "\n"))
|
|
|
|
*/
|
2024-12-12 02:05:47 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-12-18 20:08:48 -06:00
|
|
|
if check.ParseGoSum() {
|
|
|
|
return true
|
2024-12-13 02:21:39 -06:00
|
|
|
}
|
2025-01-19 10:48:16 -06:00
|
|
|
log.Info("ParseGoSum() failed", check.GetGoPath())
|
2024-12-18 20:08:48 -06:00
|
|
|
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 {
|
2025-01-19 11:51:54 -06:00
|
|
|
log.Info("fixGoDeps() START", check.GetGoPath())
|
|
|
|
log.Info("fixGoDeps() START", check.GetGoPath())
|
|
|
|
log.Info("fixGoDeps() START", check.GetGoPath())
|
2024-12-13 02:21:39 -06:00
|
|
|
var good bool = true
|
2024-12-18 20:08:48 -06:00
|
|
|
if !runGoClean(check, "--strict") {
|
2025-01-19 11:51:54 -06:00
|
|
|
log.Info("fixGoDeps() runGoClean() strict failed", check.GetGoPath())
|
|
|
|
log.Info("fixGoDeps() runGoClean() strict failed", check.GetGoPath())
|
|
|
|
log.Info("fixGoDeps() runGoClean() strict failed", check.GetGoPath())
|
2024-12-13 02:21:39 -06:00
|
|
|
return false
|
|
|
|
}
|
2024-12-02 07:00:28 -06:00
|
|
|
// 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())
|
2024-12-02 07:00:28 -06:00
|
|
|
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())
|
2024-12-01 17:36:34 -06:00
|
|
|
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())
|
2024-12-03 03:18:27 -06:00
|
|
|
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)
|
2024-12-01 17:36:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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 {
|
2024-12-17 07:03:17 -06:00
|
|
|
me.release.repo.SetText(check.GetGoPath())
|
2024-12-03 18:00:42 -06:00
|
|
|
me.release.status.SetText(s)
|
|
|
|
me.release.notes.SetText(note)
|
2024-12-17 18:48:45 -06:00
|
|
|
me.current = check
|
2024-12-03 18:00:42 -06:00
|
|
|
me.release.version.SetText(check.GetTargetVersion())
|
|
|
|
me.release.releaseVersionB.SetText("release version " + check.GetTargetVersion())
|
|
|
|
me.release.openrepo.Enable()
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|