summaryrefslogtreecommitdiff
path: root/prepareReleaseNew.go
blob: 667f7b1b25419ae0246586c23bf8b8b8ce4d2f47 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main

import (
	"errors"
	"fmt"

	"go.wit.com/lib/env"
	"go.wit.com/lib/protobuf/argvpb"
	"go.wit.com/lib/protobuf/gitpb"
	"go.wit.com/log"
)

func rePrepareReleaseNew(check *gitpb.Repo) error {
	// me.forge.RillFuncError(rillRestore)

	if me.forge.Config.IsReadOnly(check.GetGoPath()) {
		// can't release readonly repos
		return nil
	}

	if check.IsDirty() {
		return errors.New("dirty")
	}

	master := check.GetMasterVersion()
	lastTag := check.GetLastTag()

	if me.forge.Config.IsPrivate(check.GetGoPath()) {
		if master != lastTag {
			return errors.New("WARNING: private repo")

		}
		return nil
	}
	// this is detailed. It makes sure the go.* files are absolutely perfect
	if err := checkPublishedGodeps(check); err != nil {
		// this means the published godeps are no longer up to date
		// forceReleaseVersion(check)
		// log.Info("checkPublishedGodeps failed with err", check.GetGoPath(), err)
		return err
	}

	// if master != lastTag, always increment
	if master != lastTag {
		newmhash := check.GetTagHash(master)
		oldlhash := check.GetTagHash(lastTag)
		if newmhash == oldlhash {
			// they are actually equal
			return nil
		}
		b1, err := check.CountDiffObjects(oldlhash, newmhash)
		if err != nil {
			argvpb.BadExit("countdiff wrong", err)
		}
		b2, err := check.CountDiffObjects(newmhash, oldlhash)
		if err != nil {
			argvpb.BadExit("countdiff wrong", err)
		}
		if b1 != 0 {
			log.Printf("HASH ERROR       %-50s tag %s  < %s\n", check.GetGoPath(), newmhash, oldlhash)
			log.Info("old vs new count", b1, b2, "git merge", oldlhash)
		}

		if b1 == 0 && b2 == 0 {
			log.Info("got to identical repo", check.GetGoPath(), b1, b2)
			log.Info("got to identical repo", check.GetGoPath(), oldlhash, newmhash)
			// actually identical. do nothing
			return nil
		}
		if gitpb.IsGoTagVersionGreater(lastTag, master) {
			// this function is not right really. the hash error above should catch it correctly
			// log.Printf("PROBABLY NOT NEE %-50s tag %s  < %s\n", check.GetGoPath(), lastTag, master)
			s := fmt.Sprintf("gitpb.IsGoTagVersionGreater() LAST TAG %s != master %s", lastTag, master)
			return errors.New(s)
		}
		log.Printf("NEED RELEASE FOR TAG %-50s tag %s != %s\n", check.GetGoPath(), master, lastTag)
		// forceReleaseVersion(check)
		return errors.New("master != lastTag")
	}

	if check.GetRepoType() == "protobuf" {
		if env.True("--protobuf") {
			// if --protobuf, this will force upgrade each one
			s := log.Sprintf("NEED RELEASE FOR TYPE because --protobuf")
			return errors.New(s)
		}
	}

	// if the repo is a go binary or plugin for a new release for
	// any library version change
	//		if check.GetRepoType() == "binary" || check.GetRepoType() == "plugin" {
	// check if the package dependancies changed, if so, re-publish
	if err := finalGoDepsCheckOk(check); err == nil {
		// log.Printf("go.sum is perfect! %s\n", check.GetGoPath())
		return nil
	} else {
		// go.sum has some version that isn't the current version
		return err
	}
	return nil
}

// checks the published go.* files in ~/go/pkg/mod
// checks the go.* files currently on disk in ~/go/src
// TODO: compare these to each other // TODO: this is probably the missing piece to this whole thing not working right yet
func checkPublishedGodeps(repo *gitpb.Repo) error {
	godepsOld, err := repo.GoSumFromPkgDir()
	if err != nil {
		return err
	}
	if godepsOld != nil {
		if err := testGoDepsCheckOk(godepsOld); err != nil {
			return err
		}
	}
	godepsNew, err := repo.GoSumFromRepo()
	if err != nil {
		return err
	}
	if godepsOld == nil {
		if godepsNew == nil {
			// is primative. probably very certainly so. this check seems to work
			// log.Printf("%s published godeps == nil && real == nil\n", repo.GetGoPath())
			// s := log.Sprintf("PRIMATIVE library? published godeps == nil && real == nil")
			// return errors.New(s)
			return nil
		} else {
			return fmt.Errorf("published godeps == nil vs real != nil")
		}
	}
	if err := testGoDepsCheckOk(godepsNew); err != nil {
		return err
	}
	return nil
}