mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-13 18:15:34 +00:00
build: add dynamic version injection via ldflags and Makefile
- Add cmd.Version variable set at build time via -ldflags - Fix Dockerfile ldflags path to use cmd.Version instead of main.version - Add Makefile with auto-detection from git tags (git describe) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
6066adc15a
commit
a0ef0c2f91
3 files changed
+22
-2
No files matched your search
+1
-1
@@ -26,7 +26,7 @@ RUN set -eux; \
|
||||
fi; \
|
||||
if [ -n "$TAGS" ]; then TAGS="-tags $TAGS"; fi; \
|
||||
CGO_ENABLED=0 GOOS=linux \
|
||||
go build -ldflags="-s -w -X main.version=${VERSION}" \
|
||||
go build -ldflags="-s -w -X github.com/nextlevelbuilder/goclaw/cmd.Version=${VERSION}" \
|
||||
${TAGS} -o /out/goclaw .
|
||||
|
||||
# ── Stage 2: Runtime ──
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
|
||||
LDFLAGS = -s -w -X github.com/nextlevelbuilder/goclaw/cmd.Version=$(VERSION)
|
||||
BINARY = goclaw
|
||||
|
||||
.PHONY: build run clean version
|
||||
|
||||
build:
|
||||
CGO_ENABLED=0 go build -ldflags="$(LDFLAGS)" -o $(BINARY) .
|
||||
|
||||
run: build
|
||||
./$(BINARY)
|
||||
|
||||
clean:
|
||||
rm -f $(BINARY)
|
||||
|
||||
version:
|
||||
@echo $(VERSION)
|
||||
+4
-1
@@ -9,6 +9,9 @@ import (
|
||||
"github.com/nextlevelbuilder/goclaw/pkg/protocol"
|
||||
)
|
||||
|
||||
// Version is set at build time via -ldflags "-X github.com/nextlevelbuilder/goclaw/cmd.Version=v1.0.0"
|
||||
var Version = "dev"
|
||||
|
||||
var (
|
||||
cfgFile string
|
||||
verbose bool
|
||||
@@ -46,7 +49,7 @@ func versionCmd() *cobra.Command {
|
||||
Use: "version",
|
||||
Short: "Print version information",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Printf("goclaw v0.2.0 (protocol %d)\n", protocol.ProtocolVersion)
|
||||
fmt.Printf("goclaw %s (protocol %d)\n", Version, protocol.ProtocolVersion)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user