use build info

This commit is contained in:
Dan Ballard 2014-12-11 21:47:29 -08:00
parent a1c017545b
commit c08f283f80
2 changed files with 8 additions and 12 deletions

View File

@ -12,9 +12,9 @@ import (
var buildUsage = `
warren build - Runs go build and populates the following variables:
Build.GitBranch from git
Build.GitHash from git
Build.Date from system time
BuildGitBranch from git
BuildGitHash from git
BuildDate from system time
`
var buildCmd = &Command{
@ -32,7 +32,7 @@ func buildRun(cmd *Command, args ...string) {
}
date := time.Now().Format(time.RFC3339)
gobuild := exec.Command("go", "build", "-ldflags", fmt.Sprintf("-X main.Build.Date %s -X main.Build.GitHash %s -X main.Build.GitBranch %s\"", date, warren.GitHash(), warren.GitBranch()))
gobuild := exec.Command("go", "build", "-ldflags", fmt.Sprintf("-X main.BuildDate %s -X main.BuildGitHash %s -X main.BuildGitBranch %s", date, warren.GitHash(), warren.GitBranch()))
gobuild.Stderr = os.Stderr
gobuild.Stdout = os.Stdout
err := gobuild.Run()

View File

@ -8,13 +8,9 @@ import (
"text/template"
)
type BuildInfo struct {
GitHash string
GitBranch string
Date string
}
var Build BuildInfo
var BuildGitHash string
var BuildGitBranch string
var BuildDate string
var usagePrefix = `
warren is a tool for building, deploying and running multiple versions of a Go server
@ -34,7 +30,7 @@ var commands = []*Command{
}
func usage() {
fmt.Println(Build.GitBranch, " ", Build.GitHash, " ", Build.Date)
fmt.Println(BuildGitBranch, " ", BuildGitHash, " ", BuildDate)
fmt.Print(usagePrefix)
usageTmpl.Execute(os.Stdout, commands)
}