mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-18 23:05:40 -04:00
try to set a more matching version number
This commit is contained in:
parent
357fc09e69
commit
4bcb13efc0
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
|||||||
.PHONY: runtime
|
.PHONY: runtime
|
||||||
|
|
||||||
VERSION = $(shell git describe --tags --abbrev=0)
|
VERSION = $(shell go run tools/build-version.go)
|
||||||
HASH = $(shell git rev-parse --short HEAD)
|
HASH = $(shell git rev-parse --short HEAD)
|
||||||
DATE = $(shell go run tools/build-date.go)
|
DATE = $(shell go run tools/build-date.go)
|
||||||
|
|
||||||
|
65
tools/build-version.go
Normal file
65
tools/build-version.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/blang/semver"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getTag(match ...string) (string, *semver.PRVersion) {
|
||||||
|
args := append([]string{
|
||||||
|
"describe", "--tags",
|
||||||
|
}, match...)
|
||||||
|
if tag, err := exec.Command("git", args...).Output(); err != nil {
|
||||||
|
return "", nil
|
||||||
|
} else {
|
||||||
|
tagParts := strings.Split(string(tag), "-")
|
||||||
|
if len(tagParts) == 3 {
|
||||||
|
if ahead, err := semver.NewPRVersion(tagParts[1]); err == nil {
|
||||||
|
return tagParts[0], &ahead
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tagParts[0], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// 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())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Get the tag of the current revision.
|
||||||
|
tag, _ := getTag("--exact-match")
|
||||||
|
if tag == versionStr {
|
||||||
|
// Seems that we are going to build a release.
|
||||||
|
// So the version number should already be correct.
|
||||||
|
fmt.Println(version.String())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we don't have any tag assume "dev"
|
||||||
|
if tag == "" {
|
||||||
|
tag = "dev"
|
||||||
|
}
|
||||||
|
// Get the most likely next version:
|
||||||
|
version.Patch = version.Patch + 1
|
||||||
|
|
||||||
|
if pr, err := semver.NewPRVersion(tag); err == nil {
|
||||||
|
// append the tag as pre-release name
|
||||||
|
version.Pre = append(version.Pre, pr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ahead != nil {
|
||||||
|
// if we know how many commits we are ahead of the last release, append that too.
|
||||||
|
version.Pre = append(version.Pre, *ahead)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(version.String())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user