Skip to content

Commit

Permalink
correctly set version, commit & date through ldflags in goreleaser co…
Browse files Browse the repository at this point in the history
…nfig. closes #186
  • Loading branch information
dannyvankooten committed Nov 20, 2018
1 parent 0888451 commit e24c06a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cli

import (
"fmt"
"os"
"strings"
"time"

log "github.com/sirupsen/logrus"
Expand All @@ -19,15 +21,16 @@ 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

// setup CLI app
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{
Expand All @@ -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)
Expand Down

0 comments on commit e24c06a

Please sign in to comment.