X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=tools%2Fbuild-version.go;h=8aaffa3d8521364e1fa90c26c8e8164d355ec838;hb=54c23cae72d7237bc898a59f79aad0acffdf0ffe;hp=a8e68d01c9eb8affb593f86a9a6d6f68f4b7507e;hpb=759c00098bd8d5cb1680e2708a838b3bf04e6ece;p=micro.git diff --git a/tools/build-version.go b/tools/build-version.go index a8e68d01..8aaffa3d 100644 --- a/tools/build-version.go +++ b/tools/build-version.go @@ -20,19 +20,27 @@ func getTag(match ...string) (string, *semver.PRVersion) { 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 tagParts[0], nil + return string(tag), nil } } 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. versionStr, ahead := getTag("--match", "v*") version, err := semver.ParseTolerant(versionStr) if err != nil { // no version tag found so just return what ever we can find. - fmt.Println(getTag()) + fmt.Println("0.0.0-unknown") return } // Get the tag of the current revision. @@ -45,11 +53,13 @@ func main() { } // If we don't have any tag assume "dev" - if tag == "" { + if tag == "" || strings.HasPrefix(tag, "nightly") { tag = "dev" } // Get the most likely next version: - version.Patch = version.Patch + 1 + if !strings.Contains(version.String(), "rc") { + version.Patch = version.Patch + 1 + } if pr, err := semver.NewPRVersion(tag); err == nil { // append the tag as pre-release name