package gitpb // does processing on the go.mod and go.sum files import ( "errors" "os" "go.wit.com/log" ) // 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() } 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 } 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") } // 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) GoDepsChangedOld(repo *Repo) (bool, error) { var upgrade bool = false 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 { 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 } } return upgrade, nil }