Skip to content

Commit

Permalink
impr: goreleaser-compatible version, commit and date
Browse files Browse the repository at this point in the history
  • Loading branch information
nalgeon committed Jan 17, 2024
1 parent 8178918 commit 02473a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ build_rev := "main"
ifneq ($(wildcard .git),)
build_rev := $(shell git rev-parse --short HEAD)
endif

build_date := $(shell date -u '+%Y%m%d')
version := $(build_date):$(build_rev)
build_date := $(shell date -u '+%Y-%m-%dT%H:%M:%S')

setup:
@go mod download
Expand All @@ -24,7 +22,7 @@ test:


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

run:
@./build/codapi
Expand Down
9 changes: 7 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ import (
"github.com/nalgeon/codapi/internal/server"
)

var Version string = "main"
// set by the build process
var (
version = "main"
commit = "none"
date = "unknown"
)

// startServer starts the HTTP API sandbox server.
func startServer(port int) *server.Server {
logx.Log("codapi %s", Version)
logx.Log("codapi %s, commit %s, built at %s", version, commit, date)
logx.Log("listening on port %d...", port)
router := server.NewRouter()
srv := server.NewServer(port, router)
Expand Down

0 comments on commit 02473a2

Please sign in to comment.