Only fetch tags if no tags are found at all

Fixes #1504
This commit is contained in:
Zachary Yedidia
2020-02-12 01:24:25 -05:00
parent 7d47659481
commit 5e9c6375d0

View File

@@ -12,31 +12,29 @@ func getTag(match ...string) (string, *semver.PRVersion) {
args := append([]string{ args := append([]string{
"describe", "--tags", "describe", "--tags",
}, match...) }, match...)
var tag []byte if tag, err := exec.Command("git", args...).Output(); err != nil {
var err error return "", nil
if tag, err = exec.Command("git", args...).Output(); err != nil { } else {
if _, err := exec.Command("git", "fetch", "--tags").Output(); err != nil { tagParts := strings.Split(string(tag), "-")
return "", nil if len(tagParts) == 3 {
if ahead, err := semver.NewPRVersion(tagParts[1]); err == nil {
return tagParts[0], &ahead
}
} else if len(tagParts) == 4 {
if ahead, err := semver.NewPRVersion(tagParts[2]); err == nil {
return tagParts[0] + "-" + tagParts[1], &ahead
}
} }
if tag, err = exec.Command("git", args...).Output(); err != nil {
return "", nil
}
}
tagParts := strings.Split(string(tag), "-")
if len(tagParts) == 3 {
if ahead, err := semver.NewPRVersion(tagParts[1]); err == nil {
return tagParts[0], &ahead
}
} else if len(tagParts) == 4 {
if ahead, err := semver.NewPRVersion(tagParts[2]); err == nil {
return tagParts[0] + "-" + tagParts[1], &ahead
}
}
return string(tag), nil return string(tag), nil
}
} }
func main() { func main() {
if tags, err := exec.Command("git", "tag").Output(); err != nil || len(tags) == 0 {
// no tags found -- fetch them
exec.Command("git", "fetch", "--tags").Run()
}
// Find the last vX.X.X Tag and get how many builds we are ahead of it. // Find the last vX.X.X Tag and get how many builds we are ahead of it.
versionStr, ahead := getTag("--match", "v*") versionStr, ahead := getTag("--match", "v*")
version, err := semver.ParseTolerant(versionStr) version, err := semver.ParseTolerant(versionStr)