diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a81749d..1f71bfb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,7 +35,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.22" + go-version: "1.25" - name: Build env: @@ -46,7 +46,7 @@ jobs: if [ "${{ matrix.goos }}" = "windows" ]; then BINARY="${BINARY}.exe" fi - go build -trimpath -ldflags="-s -w" -o "${BINARY}" ./cmd/server/ + go build -trimpath -ldflags="-s -w -X main.Version=${{ github.ref_name }}" -o "${BINARY}" ./cmd/server/ - name: Upload artifact uses: actions/upload-artifact@v4 diff --git a/Containerfile b/Containerfile index 1cf7107..8292a64 100644 --- a/Containerfile +++ b/Containerfile @@ -1,5 +1,5 @@ # Build stage -FROM golang:1.22-alpine AS builder +FROM golang:1.25-alpine AS builder WORKDIR /app diff --git a/Makefile b/Makefile index 582badf..3f317a4 100644 --- a/Makefile +++ b/Makefile @@ -19,10 +19,12 @@ help: @sed -n 's/^## //p' $(MAKEFILE_LIST) | column -t -s ':' ## build: Compile the binary +VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev") + build: - @echo "🔨 Building $(BINARY_NAME)..." + @echo "🔨 Building $(BINARY_NAME) $(VERSION)..." @mkdir -p $(BUILD_DIR) - go build -trimpath -ldflags="-s -w" -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PKG) + go build -trimpath -ldflags="-s -w -X main.Version=$(VERSION)" -o $(BUILD_DIR)/$(BINARY_NAME) $(MAIN_PKG) @echo "✅ Built → $(BUILD_DIR)/$(BINARY_NAME)" ## run: Build and run the server diff --git a/README.md b/README.md index 623028f..36a27a7 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

Stars Last Update - Go Version + Go Version Supported Providers Container Ready CI diff --git a/cmd/server/main.go b/cmd/server/main.go index aa6294d..667325e 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "os/signal" + "runtime/debug" "syscall" "time" @@ -18,7 +19,7 @@ import ( // Version is the current version of the Heimsense binary. // Can be overridden via -ldflags="-X main.Version=v0.1.x" -var Version = "v0.1.1" +var Version = "dev" func main() { if len(os.Args) < 2 { @@ -54,7 +55,7 @@ func main() { } os.Exit(0) case "version", "-v", "--version": - fmt.Printf("heimsense version %s\n", Version) + fmt.Printf("heimsense version %s\n", getVersion()) os.Exit(0) case "help", "-h", "--help": printHelp() @@ -191,3 +192,31 @@ func printHelp() { fmt.Println(" heimsense sync (Sync manual .env changes to Claude Code)") fmt.Println() } + +// getVersion returns the current version, optionally falling back to vcs info. +func getVersion() string { + if Version != "dev" { + return Version + } + if info, ok := debug.ReadBuildInfo(); ok { + if info.Main.Version != "(devel)" && info.Main.Version != "" { + return info.Main.Version + } + var revision, modified string + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + revision = setting.Value + } + if setting.Key == "vcs.modified" && setting.Value == "true" { + modified = "-dirty" + } + } + if revision != "" { + if len(revision) > 7 { + revision = revision[:7] + } + return fmt.Sprintf("dev-%s%s", revision, modified) + } + } + return Version +}