summaryrefslogtreecommitdiff
path: root/goDep.redoGoMod.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-13 00:19:33 -0600
committerJeff Carr <[email protected]>2024-12-13 00:19:33 -0600
commitc5f7570834f092608cd2137e966399f44aa02d36 (patch)
treed0aee40b2fffc1729b654c9cfbe65a4a0183d768 /goDep.redoGoMod.go
parentadddfad2b7418dcaec4bd6c97219b72774fe0cac (diff)
working on go-mod-clean
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'goDep.redoGoMod.go')
-rw-r--r--goDep.redoGoMod.go128
1 files changed, 36 insertions, 92 deletions
diff --git a/goDep.redoGoMod.go b/goDep.redoGoMod.go
index 8406fd4..82d5830 100644
--- a/goDep.redoGoMod.go
+++ b/goDep.redoGoMod.go
@@ -4,113 +4,57 @@ package gitpb
import (
"errors"
- "os"
-
- "go.wit.com/log"
+ "time"
)
-// remove every go.mod and go.sum
-// testing to see where this stuff is coming from
-func (repo *Repo) EraseGoMod() {
- // unset the go development ENV var to generate release files
- if ok, err := repo.strictRun([]string{"rm", "-f", "go.mod", "go.sum"}); !ok {
- log.Warn("rm go.mod go.sum failed", err)
- }
-}
-
-// poor name perhaps. It's because in most of these
-// repos you can also type "make redomod" to do the same thing
-// since it's a Makefile task that is also useful to be able to run
-// from the command line
-func (repo *Repo) RedoGoMod() (bool, error) {
- // unset the go development ENV var to generate release files
- os.Unsetenv("GO111MODULE")
- if ok, err := repo.strictRun([]string{"rm", "-f", "go.mod", "go.sum"}); !ok {
- log.Warn("rm go.mod go.sum failed", err)
- return ok, err
- }
- if ok, err := repo.strictRun([]string{"go", "mod", "init", repo.GoPath}); !ok {
- log.Warn("go mod init failed", err)
- return ok, err
- }
- if ok, err := repo.strictRun([]string{"go", "mod", "tidy"}); !ok {
- log.Warn("go mod tidy failed", err)
- return ok, err
- }
- // most things should build with golang after 1.20
- if ok, err := repo.strictRun([]string{"go", "mod", "edit", "-go=1.20"}); !ok {
- log.Warn("go mod edit failed", err)
- return ok, err
- }
- // log.Info("MakeRedomod() worked", repo.GoPath)
-
- if repo.Exists("go.sum") {
- // return the attempt to parse go.mod & go.sum
- return repo.ParseGoSum()
+// checks to see if the go.sum and go.mod files
+// match the repo.pb information
+func (repo *Repo) ValidGoSum() error {
+ if repo.GoPrimitive {
+ // repo thinks it is primitive but has a go.sum file
+ if repo.Exists("go.sum") {
+ return errors.New("GoPrimitive == true, but go.sum exists")
+ }
+ mtime, err := repo.mtime("go.mod")
+ if err == nil {
+ return err
+ }
+ if mtime != repo.LastGoDep.AsTime() {
+ return errors.New("go.mod mtime mis-match")
+ }
}
- repo.GoDeps = new(GoDeps)
- repo.GoPrimitive = false
-
- ok, err := repo.IsPrimitive()
- if err != nil {
- // this means this repo does not depend on any other package
- log.Info("PRIMATIVE repo error:", repo.GoPath, "err =", err)
- return false, err
+ mtime, err := repo.mtime("go.sum")
+ if err == nil {
+ return err
}
- if ok {
- // this means the repo is primitive so there is no go.sum
- repo.GoPrimitive = true
- return true, nil
+ if mtime != repo.LastGoDep.AsTime() {
+ return errors.New("go.sum mtime mis-match")
}
- // this should never happen
- return false, errors.New("MakeRedomod() logic failed")
+ return nil
}
-// returns true if the last published
func (repo *Repo) GoDepsLen() int {
if repo.GoDeps == nil {
return 0
}
- return repo.GoDeps.Len()
+ return len(repo.GoDeps.GoDeps)
}
-// returns true if the last published
-func (repo *Repo) PublishedLen() int {
- if repo.Published == nil {
- return 0
- }
- return repo.Published.Len()
+func (repo *Repo) LastGitPull() (time.Time, error) {
+ return repo.mtime(".git/FETCH_HEAD")
}
-// returns true if the last published
-func (all *Repos) GoDepsChangedOld(repo *Repo) (bool, error) {
- var upgrade bool = false
- if repo.GoDeps == nil {
- repo.RedoGoMod()
- }
- if repo.GoDeps.Len() == 0 {
- repo.RedoGoMod()
+func (repo *Repo) GoSumAge() (time.Duration, error) {
+ var mtime time.Time
+ var err error
+ mtime, err = repo.mtime("go.sum")
+ if err == nil {
+ return time.Since(mtime), nil
}
- log.Printf("current repo %s go dependancy count: %d", repo.GetGoPath(), repo.GoDeps.Len())
- deps := repo.GoDeps.SortByGoPath()
- for deps.Scan() {
- depRepo := deps.Next()
- if repo.Published == nil {
- return false, errors.New("repo published deps info is nil")
- }
- found := repo.Published.FindByGoPath(depRepo.GetGoPath())
- if found == nil {
- log.Printf("dep %-50s %-10s vs %-10s", depRepo.GetGoPath(), depRepo.GetVersion(), "NEW")
- upgrade = true
- continue
- // return upgrade, errors.New("new repo added " + depRepo.GetGoPath())
- }
- if depRepo.GetVersion() == found.GetVersion() {
- // log.Printf("deps %-50s %-10s vs %-10s", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetVersion())
- } else {
- log.Printf("dep %-50s %-10s vs %-10s BROKEN", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetVersion())
- upgrade = true
- }
+ mtime, err = repo.mtime("go.mod")
+ if err == nil {
+ return time.Since(mtime), nil
}
- return upgrade, nil
+ now := time.Now()
+ return time.Since(now), errors.New(repo.GoPath + " go.mod missing")
}