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
|
package main
import (
"os"
"path/filepath"
"go.wit.com/log"
)
func CheckReady() bool {
if me.current == nil {
log.Info("find the next repo first")
return false
}
goSumS := me.current.GoState()
dirtyS := me.current.State()
lastS := me.current.Status.GetLastTagVersion()
currentS := me.current.Status.GetCurrentBranchVersion()
var targetS string
targetS = me.release.version.String()
log.Info("repo:", me.current.State(), goSumS, dirtyS, lastS, currentS, targetS)
if goSumS == "RELEASED" {
return true
}
if me.current.Status.IsPrimitive() {
if targetS == lastS {
me.current.SetGoState("RELEASED")
}
return true
}
if goSumS == "UNRELEASED" {
return true
}
if goSumS == "READY" {
if targetS == lastS {
me.current.SetGoState("RELEASED")
return true
}
if lastS == currentS {
me.current.SetGoState("UNRELEASED")
}
return true
}
me.current.SetGoState("NOT READY")
if me.current.Status.ReadOnly() {
log.Info("\trepo is read only")
return false
}
if targetS == lastS {
log.Info("\trepo is already done", lastS, "=", targetS)
me.current.SetGoState("READY")
return true
}
if lastS == currentS {
log.Info("\trepo is already done", lastS, "=", targetS)
me.current.SetGoState("READY")
return true
}
if goSumS == "BAD" {
log.Info("\trepo is ready", me.current.State(), "BAD == BAD")
} else {
log.Info("\trepo is ready maybe", me.current.State(), "BAD !=", goSumS)
}
if me.current.Status.CheckDirty() {
log.Info("\trepo is dirty")
return false
} else {
log.Info("\trepo is ready", me.current.State(), "not dirty")
}
fullpath := filepath.Join(me.goSrcPwd.String(), me.current.State())
testf := filepath.Join(fullpath, "go.mod")
if Exists(testf) {
log.Info("\trepo is not ready. go.mod exists")
return false
}
testf = filepath.Join(fullpath, "go.sum")
if Exists(testf) {
log.Info("\trepo is not ready. go.sum exists")
return false
}
testf = filepath.Join(fullpath, "LICENSE")
if !Exists(testf) {
log.Info("\trepo is not ready. missing LICENSE")
return false
}
// final checks here
if dirtyS == "unchanged" {
log.Info("\trepo is ready", me.current.Name(), "unchanged")
} else {
log.Info("\trepo is not ready", dirtyS, "!= 'unchanged'")
return false
}
curName := me.current.Status.GetCurrentBranchName()
mName := me.current.Status.GetMasterBranchName()
if curName == mName {
log.Info("\trepo is ready working from main branch", curName, "=", mName)
} else {
log.Info("\trepo is not ready main branch", curName, "!=", mName)
return false
}
me.current.SetGoState("READY")
return true
}
// returns true if the file exists
func Exists(file string) bool {
_, err := os.Stat(file)
if err != nil {
return false
}
return true
}
|