correctly set version, commit & date through ldflags in goreleaser config. closes #186

This commit is contained in:
Danny van Kooten 2018-11-20 09:25:24 +01:00
parent 0888451e70
commit e24c06aadd
4 changed files with 9 additions and 6 deletions

View File

@ -14,7 +14,7 @@ builds:
- 386
- arm64
ldflags:
- -extldflags "-static"
- -extldflags "-static" -s -w -X "main.version={{.Version}}" -X "main.commit={{.Commit}}" -X "main.date={{.Date}}"
hooks:
pre: packr
post: packr clean

View File

@ -1,5 +1,5 @@
EXECUTABLE := fathom
LDFLAGS += -extldflags "-static" -X "main.version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.commit=$(shell git rev-parse HEAD)"
LDFLAGS += -extldflags "-static" -X "main.version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.commit=$(shell git rev-parse HEAD)" -X "main.date=$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
MAIN_PKG := ./main.go
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
ASSET_SOURCES ?= $(shell find assets/src/. -type f)

View File

@ -14,7 +14,7 @@ var (
)
func main() {
err := cli.Run(version)
err := cli.Run(version, commit, date)
if err != nil {
fmt.Print(err)
os.Exit(1)

View File

@ -1,7 +1,9 @@
package cli
import (
"fmt"
"os"
"strings"
"time"
log "github.com/sirupsen/logrus"
@ -19,7 +21,8 @@ type App struct {
// CLI application
var app *App
func Run(v string) error {
// Run parses the CLI arguments & run application command
func Run(version string, commit string, buildDate string) error {
// force all times in UTC, regardless of server timezone
time.Local = time.UTC
@ -27,7 +30,7 @@ func Run(v string) error {
app = &App{cli.NewApp(), nil, nil}
app.Name = "Fathom"
app.Usage = "simple & transparent website analytics"
app.Version = v
app.Version = fmt.Sprintf("%v, commit %v, built at %v", strings.TrimPrefix(version, "v"), commit, buildDate)
app.HelpName = "fathom"
app.Flags = []cli.Flag{
cli.StringFlag{
@ -45,7 +48,7 @@ func Run(v string) error {
}
if len(os.Args) < 2 || os.Args[1] != "--version" {
log.Printf("%s %s", app.Name, app.Version)
log.Printf("%s version %s", app.Name, app.Version)
}
err := app.Run(os.Args)