Skip to content

Commit e24c06a

Browse files
correctly set version, commit & date through ldflags in goreleaser config. closes #186
1 parent 0888451 commit e24c06a

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ builds:
1414
- 386
1515
- arm64
1616
ldflags:
17-
- -extldflags "-static"
17+
- -extldflags "-static" -s -w -X "main.version={{.Version}}" -X "main.commit={{.Commit}}" -X "main.date={{.Date}}"
1818
hooks:
1919
pre: packr
2020
post: packr clean

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
EXECUTABLE := fathom
2-
LDFLAGS += -extldflags "-static" -X "main.version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.commit=$(shell git rev-parse HEAD)"
2+
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')"
33
MAIN_PKG := ./main.go
44
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
55
ASSET_SOURCES ?= $(shell find assets/src/. -type f)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var (
1414
)
1515

1616
func main() {
17-
err := cli.Run(version)
17+
err := cli.Run(version, commit, date)
1818
if err != nil {
1919
fmt.Print(err)
2020
os.Exit(1)

pkg/cli/cli.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package cli
22

33
import (
4+
"fmt"
45
"os"
6+
"strings"
57
"time"
68

79
log "github.com/sirupsen/logrus"
@@ -19,15 +21,16 @@ type App struct {
1921
// CLI application
2022
var app *App
2123

22-
func Run(v string) error {
24+
// Run parses the CLI arguments & run application command
25+
func Run(version string, commit string, buildDate string) error {
2326
// force all times in UTC, regardless of server timezone
2427
time.Local = time.UTC
2528

2629
// setup CLI app
2730
app = &App{cli.NewApp(), nil, nil}
2831
app.Name = "Fathom"
2932
app.Usage = "simple & transparent website analytics"
30-
app.Version = v
33+
app.Version = fmt.Sprintf("%v, commit %v, built at %v", strings.TrimPrefix(version, "v"), commit, buildDate)
3134
app.HelpName = "fathom"
3235
app.Flags = []cli.Flag{
3336
cli.StringFlag{
@@ -45,7 +48,7 @@ func Run(v string) error {
4548
}
4649

4750
if len(os.Args) < 2 || os.Args[1] != "--version" {
48-
log.Printf("%s %s", app.Name, app.Version)
51+
log.Printf("%s version %s", app.Name, app.Version)
4952
}
5053

5154
err := app.Run(os.Args)

0 commit comments

Comments
 (0)