Update version to use a nicer date format

This commit is contained in:
Tony Blyler 2016-05-16 22:53:08 -04:00
parent 31bf3fca93
commit 61f7a52ef1
No known key found for this signature in database
GPG key ID: 25C9D3A655D1A65C
2 changed files with 13 additions and 3 deletions

View file

@ -4,12 +4,12 @@ go:
- 1.6 - 1.6
env: env:
- DATE=$(date -u '+%Y/%m/%d %H:%M:%S') BUILD_VERSION=$(if [ -n $TRAVIS_TAG ]; then echo -n $TRAVIS_COMMIT; else echo -n $TRAVIS_TAG; fi) - DATE=$(date '+%s') BUILD_VERSION='v0.1.0'
before_install: before_install:
- go get github.com/mitchellh/gox - go get github.com/mitchellh/gox
- go get github.com/tcnksm/ghr - go get github.com/tcnksm/ghr
after_success: after_success:
- gox -ldflags "-X 'main.buildVersion=$BUILD_VERSION' -X 'main.buildDate=$DATE'" -output "dist/hoarder_{{.OS}}_{{.Arch}}" ./cmd/hoarder - gox -ldflags "-X 'main.buildVersion=$BUILD_VERSION ($TRAVIS_COMMIT)' -X 'main.buildDate=$DATE'" -output "dist/hoarder_{{.OS}}_{{.Arch}}" ./cmd/hoarder
- ghr --username tblyler --token $GITHUB_TOKEN --replace --prerelease --debug v0.1.0 dist/ - ghr --username tblyler --token $GITHUB_TOKEN --replace --prerelease --debug $BUILD_VERSION dist/

View file

@ -9,6 +9,8 @@ import (
"log" "log"
"os" "os"
"os/signal" "os/signal"
"strconv"
"time"
) )
var buildVersion = "Unknown" var buildVersion = "Unknown"
@ -20,6 +22,14 @@ func main() {
flag.Parse() flag.Parse()
if *version { if *version {
dateUnix, err := strconv.ParseInt(buildDate, 10, 64)
if err == nil {
date := time.Unix(dateUnix, 0)
if !date.IsZero() {
buildDate = date.UTC().Format(time.UnixDate)
}
}
fmt.Printf("%s\n%s\n", buildVersion, buildDate) fmt.Printf("%s\n%s\n", buildVersion, buildDate)
os.Exit(0) os.Exit(0)
} }