package forgepb import ( "errors" "fmt" "strings" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) // DOES NOT MODIFY ANYTHING // // this is a final check to make sure, before pushing // a golang repo, that the go.sum file has the correct // and current version of every package // // it re-scans the go.sum file. DOES NOT MODIFY ANYTHING // this is the last thing to run to double check everything // before 'git tag' or git push --tags func (f *Forge) FinalGoDepsCheckOk(check *gitpb.Repo, verbose bool) error { if check == nil { return errors.New("FinalGoDepsCheckOk() boo, check == nil") } // parse the go.mod and go.sum files if !check.ParseGoSum() { return fmt.Errorf("forge.ParseGoSum() failed. go.mod & go.sum are broken") } if check.GetGoPrimitive() { return nil } deps := check.GoDeps.SortByGoPath() for deps.Scan() { depRepo := deps.Next() found := f.FindByGoPath(depRepo.GetGoPath()) if found == nil { if f.CheckOverride(depRepo.GetGoPath()) { // skip this gopath because it's probably broken forever continue } return fmt.Errorf("dep not found: %s", depRepo.GetGoPath()) } if depRepo.GetVersion() == found.GetMasterVersion() { // log.Printf("%-48s error ?? %-10s vs %-10s\n", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion()) continue } // log.Info("found dep", depRepo.GetGoPath()) if depRepo.GetVersion() != found.GetTargetVersion() { check := f.FindByGoPath(depRepo.GetGoPath()) if f.Config.IsReadOnly(check.GetGoPath()) { if verbose { log.Printf("%-48s ok error .%s. vs .%s. (ignoring read-only repo)\n", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion()) } } else { if f.CheckOverride(depRepo.GetGoPath()) { if verbose { log.Printf("%-48s ok error .%s. vs .%s. (forge.CheckOverride())\n", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion()) } // skip this gopath because it's probably broken forever continue } else { // log.Printf("%-48s error ?? %-10s vs %-10s\n", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion()) // log.Printf("%-48s error %10s vs %10s\n", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion()) return fmt.Errorf("%-48s error %10s vs %10s", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion()) } } } } return nil } func (f *Forge) CheckOverride(gopath string) bool { if gopath == "cloud.google.com/go" { // log.Info("CheckOverride() is ignoring", gopath) return true } if gopath == "bou.ke/monkey" { // log.Info("CheckOverride() is ignoring", gopath) return true } if gopath == "github.com/posener/complete/v2" { // log.Info("CheckOverride() is ignoring", gopath) return true } if strings.HasPrefix(gopath, "github.com/go-gl") { // log.Info("CheckOverride() is ignoring", gopath) return true } if strings.HasPrefix(gopath, "google.golang.org") { // log.Info("CheckOverride() is ignoring", gopath) return true } if strings.HasPrefix(gopath, "go.opencensus.io") { // log.Info("CheckOverride() is ignoring", gopath) return true } if strings.HasPrefix(gopath, "github.com/nicksnyder/go-i18n") { // log.Info("CheckOverride() is ignoring", gopath) return true } // fuckit for now. just blacklist github.com if strings.HasPrefix(gopath, "github.com/") { // log.Info("CheckOverride() is ignoring", gopath) return true } return false } func (f *Forge) TestGoDepsCheckOk(godeps *gitpb.GoDeps, verbose bool) error { if godeps == nil { return errors.New("forge.TestGoDepsCheckOk() godeps == nil") } all := godeps.SortByGoPath() for all.Scan() { depRepo := all.Next() found := f.FindByGoPath(depRepo.GetGoPath()) if found == nil { if f.CheckOverride(depRepo.GetGoPath()) { // skip this gopath because it's probably broken forever continue } return fmt.Errorf("dep not found: %s", depRepo.GetGoPath()) } if depRepo.GetVersion() == found.GetMasterVersion() { // log.Printf("%-48s error ?? %-10s vs %-10s\n", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion()) continue } // log.Info("found dep", depRepo.GetGoPath()) if depRepo.GetVersion() != found.GetTargetVersion() { check := f.FindByGoPath(depRepo.GetGoPath()) if f.Config.IsReadOnly(check.GetGoPath()) { if verbose { log.Printf("%-48s ok error .%s. vs .%s. (ignoring read-only repo)\n", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion()) } } else { if f.CheckOverride(depRepo.GetGoPath()) { if verbose { log.Printf("%-48s ok error .%s. vs .%s. (forge.CheckOverride())\n", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion()) } // skip this gopath because it's probably broken forever continue } else { // log.Printf("%-48s error ?? %-10s vs %-10s\n", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion()) // log.Printf("%-48s error %10s vs %10s\n", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion()) return fmt.Errorf("%-48s error %10s vs %10s", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion()) } } } } return nil }