diff --git a/.travis.yml b/.travis.yml index a3c2d9d..0f2ce7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,12 +4,12 @@ go: - 1.6 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: - go get github.com/mitchellh/gox - go get github.com/tcnksm/ghr after_success: - - gox -ldflags "-X 'main.buildVersion=$BUILD_VERSION' -X 'main.buildDate=$DATE'" -output "dist/hoarder_{{.OS}}_{{.Arch}}" ./cmd/hoarder - - ghr --username tblyler --token $GITHUB_TOKEN --replace --prerelease --debug v0.1.0 dist/ + - 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 $BUILD_VERSION dist/ diff --git a/cmd/hoarder/main.go b/cmd/hoarder/main.go index 1054011..5cbe29a 100644 --- a/cmd/hoarder/main.go +++ b/cmd/hoarder/main.go @@ -9,6 +9,8 @@ import ( "log" "os" "os/signal" + "strconv" + "time" ) var buildVersion = "Unknown" @@ -20,6 +22,14 @@ func main() { flag.Parse() 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) os.Exit(0) }