Switches to native Go build info for versioning
Simplifies the version command and Makefile by removing manual ldflags injection. The application now relies entirely on Go's built-in VCS metadata embedding to extract version, commit, and date information, ensuring accurate reporting across all build methods.
This commit is contained in:
28
Makefile
28
Makefile
@@ -1,24 +1,14 @@
|
||||
.PHONY: build install test clean version
|
||||
.PHONY: build install test coverage clean
|
||||
|
||||
# Get version from git tag, fallback to dev
|
||||
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
||||
DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
# Ldflags to inject version information
|
||||
LDFLAGS := -ldflags "-X git.membo.co.uk/dtomlinson/gitlocal/cmd.Version=$(VERSION) \
|
||||
-X git.membo.co.uk/dtomlinson/gitlocal/cmd.Commit=$(COMMIT) \
|
||||
-X git.membo.co.uk/dtomlinson/gitlocal/cmd.Date=$(DATE)"
|
||||
|
||||
# Build the binary
|
||||
# Build the binary (Go automatically embeds VCS info)
|
||||
build:
|
||||
@echo "Building gitlocal $(VERSION)..."
|
||||
go build $(LDFLAGS) -o gitlocal .
|
||||
@echo "Building gitlocal..."
|
||||
go build -o gitlocal .
|
||||
|
||||
# Install to $GOPATH/bin
|
||||
install:
|
||||
@echo "Installing gitlocal $(VERSION)..."
|
||||
go install $(LDFLAGS) .
|
||||
@echo "Installing gitlocal..."
|
||||
go install .
|
||||
|
||||
# Run tests
|
||||
test:
|
||||
@@ -35,9 +25,3 @@ coverage:
|
||||
clean:
|
||||
@echo "Cleaning..."
|
||||
rm -f gitlocal coverage.out
|
||||
|
||||
# Show version that would be built
|
||||
version:
|
||||
@echo "Version: $(VERSION)"
|
||||
@echo "Commit: $(COMMIT)"
|
||||
@echo "Date: $(DATE)"
|
||||
|
||||
Reference in New Issue
Block a user