summaryrefslogtreecommitdiff
path: root/finalGoSumCheck.go
blob: f32f9053c200d8bf0b9179ee526b65774c4c1565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package forgepb

import (
	"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) bool {
	var good bool = true
	if check == nil {
		log.Info("boo, check == nil")
		return false
	}

	// parse the go.mod and go.sum files
	if !check.ParseGoSum() {
		log.Info("forge.FinalGoDepsCheckOk() failed")
		return false
	}

	if check.GetGoPrimitive() {
		return true
	}

	log.Printf("current repo %s go dependancy count: %d", check.GetGoPath(), check.GoDepsLen())
	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
			}
			log.Info("not found:", depRepo.GetGoPath())
			good = false
			continue
		}
		// log.Info("found dep", depRepo.GetGoPath())
		if depRepo.GetVersion() != found.GetTargetVersion() {
			check := f.FindByGoPath(depRepo.GetGoPath())
			if f.Config.IsReadOnly(check.GetGoPath()) {
				log.Printf("%-48s  ok error .%s. vs .%s. (ignoring read-only repo)", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion())
			} else {
				if f.CheckOverride(depRepo.GetGoPath()) {
					log.Printf("%-48s  ok error .%s. vs .%s. (forge.CheckOverride())", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion())
					// skip this gopath because it's probably broken forever
					continue
				} else {
					log.Printf("%-48s     error %10s vs %10s", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion())
					good = false
				}
			}
		}
	}
	return good
}

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
}