From 7bf54b9e8362996c5637b5ae0b7352daabff8c7c Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 13 Mar 2026 19:56:42 +0000 Subject: [PATCH] Use `debug.ReadBuildInfo` to determine version for `go run` (#155) *Written by Claude on behalf of @silverwind* When installed via `go run module@version` or `go install module@version`, the Go toolchain embeds the module version in the binary. Use `debug.ReadBuildInfo` to read it as a fallback when `Version` has not been set via ldflags, so that `go run gitea.com/gitea/gitea-mcp@latest` will reports the latest tag version instead of `dev`. Reviewed-on: https://gitea.com/gitea/gitea-mcp/pulls/155 Reviewed-by: Lunny Xiao Co-authored-by: silverwind Co-committed-by: silverwind --- main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.go b/main.go index fa5c489..f6b862d 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "runtime/debug" + "gitea.com/gitea/gitea-mcp/cmd" "gitea.com/gitea/gitea-mcp/pkg/flag" ) @@ -8,6 +10,11 @@ import ( var Version = "dev" func init() { + if Version == "dev" { + if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" && info.Main.Version != "(devel)" { + Version = info.Main.Version + } + } flag.Version = Version }