add-date-to unstable

This commit is contained in:
H 2019-05-02 08:57:02 -05:00 committed by H
parent 5036992b06
commit 4263000f2c
2 changed files with 28 additions and 5 deletions

View file

@ -98,11 +98,7 @@ func NewApp(gitCommit, usage string) *cli.App {
app.Author = "" app.Author = ""
//app.Authors = nil //app.Authors = nil
app.Email = "" app.Email = ""
app.Version = params.VersionWithMeta app.Version = params.VersionWithCommit(gitCommit)
if len(gitCommit) >= 8 {
app.Version += "-" + gitCommit[:8]
}
app.Usage = usage
return app return app
} }

View file

@ -18,6 +18,10 @@ package params
import ( import (
"fmt" "fmt"
"log"
"os/exec"
"strconv"
"time"
) )
const ( const (
@ -60,5 +64,28 @@ func VersionWithCommit(gitCommit string) string {
if len(gitCommit) >= 8 { if len(gitCommit) >= 8 {
vsn += "-" + gitCommit[:8] vsn += "-" + gitCommit[:8]
} }
if VersionMeta != "stable" {
d := getCommitDate(gitCommit)
if d != "" {
vsn += "-" + d
}
}
return vsn return vsn
} }
func getCommitDate(commit string) string {
if commit != "" {
out, err := exec.Command("git", "show", "-s", "--format=%ct", commit).CombinedOutput()
if err != nil {
log.Println("Could not get gitCommit date: " + string(out))
return ""
}
ti, err := strconv.ParseInt(string(out), 10, 64)
if err != nil {
log.Println("Could not convert gitCommit date. Parsed timestap is: " + string(out))
return ""
}
return time.Unix(ti, 0).Format("20060102")
}
return ""
}