warren/cmd_build.go

43 lines
902 B
Go

package main
import (
"fmt"
"github.com/dballard/warren/src/warren"
"log"
"os"
"os/exec"
"time"
)
var buildUsage = `
warren build - Runs go build and populates the following variables:
BuildGitBranch from git
BuildGitHash from git
BuildDate from system time
`
var buildCmd = &Command{
Name: "build",
Usage: "",
Summary: "build the go server in the current directory",
Help: buildUsage,
Run: buildRun,
}
func buildRun(cmd *Command, args ...string) {
if len(args) > 0 && args[0] == "help" {
fmt.Print(cmd.Help)
return
}
date := time.Now().Format(time.RFC3339)
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()
if err != nil {
log.Fatal(err)
}
}