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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
// This is a simple example
package main
import (
"os"
"path/filepath"
"strings"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
func doRelease() bool {
log.Info("doRelease() on", release.current.Name())
// double check release version logic
if release.releaseVersionB.String() != "release version "+release.version.String() {
log.Warn("something went wrong with the release.version:", release.version.String())
return false
}
if strings.HasPrefix(release.version.String(), "v") {
log.Warn("everything is ok. version starts with v.", release.version.String())
} else {
log.Warn("version does not start with v.", release.version.String())
return false
}
switch release.current.GoState() {
case "PRIMATIVE":
log.Warn("can do PRIMATIVE", release.current.Name())
case "GOOD":
log.Warn("GOOD. lots of go.sum checks passed", release.version.String())
case "manually chosen":
log.Warn("attempting manual release", release.version.String())
/*
case "NOT READY":
log.Warn("attempting to release. TODO: recheck go.sum here", release.version.String())
log.Warn("Sleep 10")
log.Sleep(10)
case "UNRELEASED":
log.Warn("attempting to release. TODO: dig deep on go.sum here", release.version.String())
log.Warn("Sleep 10")
log.Sleep(10)
*/
default:
log.Warn("what is this?", release.version.String(), release.current.Name())
return false
}
if release.current.Status.ReadOnly() {
log.Info("sorry, it's read-only")
return true
}
if release.current.Status.CheckDirty() {
log.Info("sorry, it's still dirty")
return false
}
curName := release.current.Status.GetCurrentBranchName()
mName := release.current.Status.GetMasterBranchName()
if curName != mName {
log.Info("\trepo is not working from main branch", curName, "!=", mName)
return false
}
log.Info("\ttag and push", curName, release.version.String(), me.releaseReasonS)
var all [][]string
all = append(all, []string{"git", "add", "-f", "go.mod"})
if release.current.Status.CheckPrimativeGoMod() {
// don't add go.sum here. TODO: check for go.sum file and fail
} else {
all = append(all, []string{"git", "add", "-f", "go.sum"})
}
all = append(all, []string{"git", "commit", "-m", me.releaseReasonS})
all = append(all, []string{"git", "push"})
all = append(all, []string{"git", "tag", "-m", me.releaseReasonS, release.version.String()})
all = append(all, []string{"git", "push", "origin", release.version.String()})
if !release.current.Status.DoAll(all) {
log.Info("failed to make new release", release.version.String())
return false
}
log.Info("RELEASE OK")
// 'publish' the version to the golang package versioning system
if !doPublishVersion() {
log.Info("PUBLISH FAILED")
return false
}
log.Info("PUBLISH OK")
release.current.SetGoState("RELEASED")
// unwind and re-tag. Now that the go.mod and go.sum are published, revert
// to the development branch
if !release.current.Status.RevertMasterToDevel() {
log.Info("Revert Failed")
return false
}
// update tag
var retag [][]string
retag = append(retag, []string{"git", "tag", "--delete", release.version.String()})
retag = append(retag, []string{"git", "push", "--delete", "origin", release.version.String()})
retag = append(retag, []string{"git", "tag", "-m", me.releaseReasonS, release.version.String()})
retag = append(retag, []string{"git", "push", "origin", release.version.String()})
if !release.current.Status.DoAll(retag) {
log.Info("retag failed")
return false
}
log.Info("EVERYTHING OK. RERELEASED", release.current.Name())
// update the values in the GUI
release.current.Status.UpdateNew()
// attempt to find another repo to release
if !doReleaseFindNext() {
log.Info("doReleaseFindNext() could not find a new")
return false
}
log.Info("GOOD TO RUN ANOTHER DAY ON:", release.current.Name())
return true
}
// try to figure out if there is another package to update
func doReleaseFindNext() bool {
// scan for new repo
if findNextDirty("") {
log.Info("findNextDirty() found something")
} else {
log.Info("findNextDirty() could not find anything")
return false
}
release.current.Status.CheckSafeGoSumRemake()
if release.current.Status.MakeRedomod() {
log.Info("Redo mod ok")
} else {
log.Info("go mod tidy not ok")
return false
}
if ok, _ := release.current.Status.CheckGoSum(); ok {
log.Info("repo has go.sum requirements that are clean")
// release.current.setGoSumStatus("CLEAN")
release.status.SetValue("GOOD")
release.notes.SetValue("CheckGoSum() does not seem to lie")
return true
}
release.notes.SetValue("CheckGoSum() failed")
return false
}
// this pulls the new tag from the golang package repository
// to insert the new version
func doPublishVersion() bool {
gopath := release.current.GoPath()
cmd := []string{"go", "get", "-v", gopath + "@" + release.version.String()}
log.Info("SHOULD RUN cmd HERE:", cmd)
// right now, you can't publish this because the go.* files in this project are screwed up
if release.guireleaser == nil {
log.Info("CAN NOT SELF UPDATE HERE. cmd =", cmd)
return false
}
homeDir, _ := os.UserHomeDir()
gosum := filepath.Join(homeDir, "go/src/go.wit.com/apps/guireleaser/go.sum")
if !shell.Exists(gosum) {
log.Info("go.sum must exist here")
release.guireleaser.Status.MakeRedomod()
}
os.Unsetenv("GO111MODULE")
log.Info("TRYING TO SELF UPDATE HERE. cmd =", cmd)
err, out := release.guireleaser.Status.RunCmd(cmd)
if gopath == "go.wit.com/apps/guireleaser" {
// ignore errors on updating myself
log.Info("IGNORE SELF UPDATE ERROR. cmd =", cmd)
err = nil
}
if err == nil {
log.Info("SELF UPDATE OK. out =", out)
log.Info("SELF UPDATE WORKED")
release.current.SetGoState("RELEASED")
return true
}
return false
}
|