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:
viettranxandClaude Opus 4.6 committed 2026-02-26 10:42:54 +07:00
1 parent 6066adc15a
commit a0ef0c2f91
3 files changed
+22 -2

No files matched your search

+4 -1
View File
@@ -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)
},
}
}