Skip to content

Commit

Permalink
Apply version embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepla committed Jun 5, 2022
1 parent 2168ffa commit a82fc00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
NAME = fzwiki
BIN := bin/$(NAME)

# version e.g. v0.0.1
VERSION := $(shell git describe --tags --abbrev=0 | tr -d "v")
# commit hash of HEAD e.g. 3a913f
REVISION := $(shell git rev-parse --short HEAD)

LDFLAGS := -w \
-s \
-X "main.appVersion=$(VERSION)" \
-X "main.appRevision=$(REVISION)"

COVERAGE_OUT := .test/cover.out
COVERAGE_HTML := .test/cover.html

Expand All @@ -9,11 +20,11 @@ fmt:

.PHONY: lint
lint:
staticcheck
staticcheck ./...

.PHONY: build
build:
go build -o $(BIN)
go build -ldflags "$(LDFLAGS)" -o $(BIN)

.PHONY: test
test:
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (

type exitCode int

const (
appVersion = "0.0.9"
var (
appVersion = "unknown"
appRevision = "unknown"
appName = "fzwiki"
envNameLang = "FZWIKI_LANG"
)
Expand Down Expand Up @@ -59,7 +60,7 @@ func Main(args []string) exitCode {
}

if opts.Version {
fmt.Printf("%s: v%s\n", appName, appVersion)
fmt.Printf("%s: v%s-rev%s\n", appName, appVersion, appRevision)
return exitCodeOK
}

Expand Down

0 comments on commit a82fc00

Please sign in to comment.