fix: Add commit and branch to bd version output (github #503)

- Update Makefile install target to extract and pass git commit/branch via ldflags
- Add -X main.Commit and -X main.Branch to all build configurations in .goreleaser.yml
- Create scripts/install.sh helper for explicit version control during installation
- Add comprehensive tests for commit/branch resolution and output formatting

Fixes github #503: 'bd version' now reports as-built commit hash and branch
information regardless of installation method (make install, go install, or
released binaries from goreleaser).
This commit is contained in:
matt wilkie
2025-12-09 06:09:30 -07:00
committed by Steve Yegge
parent 48dec1fada
commit 0423fc689f
4 changed files with 322 additions and 97 deletions

View File

@@ -34,9 +34,11 @@ bench-quick:
go test -bench=. -benchtime=100ms -tags=bench -run=^$$ ./internal/storage/sqlite/ -timeout=15m
# Install bd to GOPATH/bin
install: build
install:
@echo "Installing bd to $$(go env GOPATH)/bin..."
go install ./cmd/bd
@bash -c 'commit=$$(git rev-parse HEAD 2>/dev/null || echo ""); \
branch=$$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo ""); \
go install -ldflags="-X main.Commit=$$commit -X main.Branch=$$branch" ./cmd/bd'
# Clean build artifacts and benchmark profiles
clean: