summaryrefslogtreecommitdiff
path: root/prepareRelease.go
blob: 70d829b17fd9cd280167747e5fa774f81443ff18 (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
package main

import (
	"go.wit.com/log"
)

func makePrepareRelease() {
	me.Disable()
	me.release.box.Disable()
	defer me.Enable()

	if setAllBranchesToMaster() {
		// if it succeeds, disable this button
		me.setBranchesToMasterB.Disable()
		me.release.box.Enable()
		PrintReleaseReport("", "")
	} else {
		log.Info("setAllBranchesToMaster() failed")
	}

	// reset all the target versions back to the current version
	// incase they were saved in the repos.pb file
	all := me.forge.Repos.SortByGoPath()
	for all.Scan() {
		check := all.Next()

		// set the target version to the current master version
		curver := check.GetMasterVersion()
		check.SetTargetVersion(curver)
	}

	// run go-mod-clean on everything not readonly
	all = me.forge.Repos.SortByGoPath()
	for all.Scan() {
		check := all.Next()

		if me.forge.Config.IsReadOnly(check.GoPath) {
			// can't release readonly repos
			continue
		}

		if ok, err := check.IsPrimitive(); !ok {
			log.Info("something wrong with", check.GoPath, err)
			// no go.sum file for these
			continue
		}

		if check.Exists("go.sum") {
			// probably already ran
			continue
		}

		// run go-mod-clean on every repo to start
		if !runGoClean(check) {
			log.Info("go-mod-clean FAILED. THIS IS BAD.", check.GoPath)
		}
	}

	all = me.forge.Repos.SortByGoPath()
	for all.Scan() {
		check := all.Next()

		if me.forge.Config.IsReadOnly(check.GoPath) {
			// can't release readonly repos
			continue
		}
		// if master != lastTag, always increment
		master := check.GetMasterVersion()
		lastTag := check.GetLastTag()
		if master != lastTag {
			// if v1.2.3 change to v.1.2.4
			check.IncrementTargetRevision()
			if !runGoClean(check) {
				log.Info("go-mod-clean FAILED. THIS IS BAD.", check.GoPath)
			}
			continue
		}

		// if the repo is a go binary, try forcing new go.* files
		if check.RepoType() != "binary" {
			// master and lasttag match and it's not a binary. everything is fine
			continue
		}
		// check if the package dependancies changed, if so, re-publish
		if me.forge.FinalGoDepsCheckOk(check) {
			log.Printf("go.sum is perfect! %s\n", check.GetGoPath())
			continue
		}
		log.Printf("dependancy checks indicate a new release is needed for %s\n", check.GetGoPath())
		// if v1.2.3 change to v.1.2.4
		check.IncrementTargetRevision()
		// run go-mod-clean in each repo that needs to be updated
		if master == lastTag {
			// 'git notes' has something in it. clear it out
			check.Run([]string{"git", "notes", "remove"})
		}
		if !runGoClean(check) {
			log.Info("go-mod-clean FAILED. THIS IS BAD.", check.GoPath)
		}

	}
	if findNext() {
		log.Info("prepare release findNext() returned true")
		me.release.box.Enable()
	} else {
		log.Info("prepare release findNext() returned false")
		if findNext() {
			log.Info("prepare release findNext() returned true")
			me.release.box.Enable()
		} else {
			log.Info("prepare release findNext() returned false")
		}
	}
}