Skip to content

Commit 02473a2

Browse files
committed
impr: goreleaser-compatible version, commit and date
1 parent 8178918 commit 02473a2

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ build_rev := "main"
66
ifneq ($(wildcard .git),)
77
build_rev := $(shell git rev-parse --short HEAD)
88
endif
9-
10-
build_date := $(shell date -u '+%Y%m%d')
11-
version := $(build_date):$(build_rev)
9+
build_date := $(shell date -u '+%Y-%m-%dT%H:%M:%S')
1210

1311
setup:
1412
@go mod download
@@ -24,7 +22,7 @@ test:
2422

2523

2624
build:
27-
@go build -ldflags "-X main.Version=$(version)" -o build/codapi -v cmd/main.go
25+
@go build -ldflags "-X main.commit=$(build_rev) -X main.date=$(build_date)" -o build/codapi -v cmd/main.go
2826

2927
run:
3028
@./build/codapi

cmd/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ import (
1313
"github.com/nalgeon/codapi/internal/server"
1414
)
1515

16-
var Version string = "main"
16+
// set by the build process
17+
var (
18+
version = "main"
19+
commit = "none"
20+
date = "unknown"
21+
)
1722

1823
// startServer starts the HTTP API sandbox server.
1924
func startServer(port int) *server.Server {
20-
logx.Log("codapi %s", Version)
25+
logx.Log("codapi %s, commit %s, built at %s", version, commit, date)
2126
logx.Log("listening on port %d...", port)
2227
router := server.NewRouter()
2328
srv := server.NewServer(port, router)

0 commit comments

Comments
 (0)