2024-11-27 21:40:06 -06:00
|
|
|
package gitpb
|
|
|
|
|
|
|
|
// does processing on the go.mod and go.sum files
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"go.wit.com/log"
|
|
|
|
)
|
|
|
|
|
2024-12-03 13:25:00 -06:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-27 21:40:06 -06:00
|
|
|
// 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
|
2024-11-30 02:03:32 -06:00
|
|
|
func (repo *Repo) RedoGoMod() (bool, error) {
|
2024-11-27 21:40:06 -06:00
|
|
|
// 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
|
|
|
|
}
|
2024-11-29 21:51:30 -06:00
|
|
|
// 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
|
|
|
|
}
|
2024-11-30 02:03:32 -06:00
|
|
|
// log.Info("MakeRedomod() worked", repo.GoPath)
|
2024-11-27 21:40:06 -06:00
|
|
|
|
|
|
|
if repo.Exists("go.sum") {
|
|
|
|
// return the attempt to parse go.mod & go.sum
|
2024-12-02 05:15:39 -06:00
|
|
|
return repo.ParseGoSum()
|
2024-11-27 21:40:06 -06:00
|
|
|
}
|
2024-12-01 16:40:41 -06:00
|
|
|
repo.GoDeps = new(GoDeps)
|
2024-11-27 21:40:06 -06:00
|
|
|
repo.GoPrimitive = false
|
|
|
|
|
2024-12-03 18:03:54 -06:00
|
|
|
ok, err := repo.IsPrimitive()
|
2024-11-27 21:40:06 -06:00
|
|
|
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
|
|
|
|
}
|
|
|
|
if ok {
|
|
|
|
// this means the repo is primitive so there is no go.sum
|
|
|
|
repo.GoPrimitive = true
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
// this should never happen
|
|
|
|
return false, errors.New("MakeRedomod() logic failed")
|
|
|
|
}
|
|
|
|
|
2024-12-01 15:10:55 -06:00
|
|
|
// returns true if the last published
|
|
|
|
func (repo *Repo) GoDepsLen() int {
|
|
|
|
if repo.GoDeps == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return repo.GoDeps.Len()
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns true if the last published
|
|
|
|
func (repo *Repo) PublishedLen() int {
|
|
|
|
if repo.Published == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return repo.Published.Len()
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns true if the last published
|
|
|
|
func (all *Repos) GoDepsChanged(repo *Repo) (bool, error) {
|
2024-12-01 16:04:07 -06:00
|
|
|
var upgrade bool = false
|
2024-12-01 15:10:55 -06:00
|
|
|
if repo.GoDeps == nil {
|
|
|
|
repo.RedoGoMod()
|
|
|
|
}
|
|
|
|
if repo.GoDeps.Len() == 0 {
|
|
|
|
repo.RedoGoMod()
|
|
|
|
}
|
|
|
|
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 {
|
2024-12-01 16:04:07 -06:00
|
|
|
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
|
2024-12-01 15:10:55 -06:00
|
|
|
}
|
|
|
|
}
|
2024-12-01 16:04:07 -06:00
|
|
|
return upgrade, nil
|
2024-12-01 15:10:55 -06:00
|
|
|
}
|