From c1af510ead4437e1c2237618b8f071f8feb0847d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sat, 16 Aug 2025 11:54:15 -0700 Subject: [PATCH] feat(version): use Golang's builtin vcs feature to get commit and build date --- Makefile | 26 ++++++++++++-------------- internal/version/version.go | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 111bbe9a..4b449300 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,7 @@ APP := miniflux DOCKER_IMAGE := miniflux/miniflux VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null) -COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null) -BUILD_DATE := `date +%FT%T%z` -LD_FLAGS := "-s -w -X 'miniflux.app/v2/internal/version.Version=$(VERSION)' -X 'miniflux.app/v2/internal/version.Commit=$(COMMIT)' -X 'miniflux.app/v2/internal/version.BuildDate=$(BUILD_DATE)'" +LD_FLAGS := "-s -w -X 'miniflux.app/v2/internal/version.Version=$(VERSION)'" PKG_LIST := $(shell go list ./... | grep -v /vendor/) DB_URL := postgres://postgres:postgres@localhost/miniflux_test?sslmode=disable DOCKER_PLATFORM := amd64 @@ -40,45 +38,45 @@ export PGPASSWORD := postgres debian-packages miniflux: - @ go build -buildmode=pie -ldflags=$(LD_FLAGS) -o $(APP) main.go + @ go build -buildmode=pie -ldflags=$(LD_FLAGS) -o $(APP) miniflux-no-pie: - @ go build -ldflags=$(LD_FLAGS) -o $(APP) main.go + @ go build -ldflags=$(LD_FLAGS) -o $(APP) linux-amd64: - @ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ main.go + @ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ @ sha256sum $(APP)-$@ > $(APP)-$@.sha256 linux-arm64: - @ CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ main.go + @ CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ @ sha256sum $(APP)-$@ > $(APP)-$@.sha256 linux-armv7: - @ CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ main.go + @ CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ @ sha256sum $(APP)-$@ > $(APP)-$@.sha256 linux-armv6: - @ CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ main.go + @ CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ @ sha256sum $(APP)-$@ > $(APP)-$@.sha256 linux-armv5: - @ CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ main.go + @ CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=5 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ @ sha256sum $(APP)-$@ > $(APP)-$@.sha256 darwin-amd64: - @ GOOS=darwin GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ main.go + @ GOOS=darwin GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ @ sha256sum $(APP)-$@ > $(APP)-$@.sha256 darwin-arm64: - @ GOOS=darwin GOARCH=arm64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ main.go + @ GOOS=darwin GOARCH=arm64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ @ sha256sum $(APP)-$@ > $(APP)-$@.sha256 freebsd-amd64: - @ CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ main.go + @ CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ @ sha256sum $(APP)-$@ > $(APP)-$@.sha256 openbsd-amd64: - @ GOOS=openbsd GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ main.go + @ GOOS=openbsd GOARCH=amd64 go build -ldflags=$(LD_FLAGS) -o $(APP)-$@ @ sha256sum $(APP)-$@ > $(APP)-$@.sha256 build: linux-amd64 linux-arm64 linux-armv7 linux-armv6 linux-armv5 darwin-amd64 darwin-arm64 freebsd-amd64 openbsd-amd64 diff --git a/internal/version/version.go b/internal/version/version.go index e028add4..69bd7d1e 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -3,9 +3,36 @@ package version // import "miniflux.app/v2/internal/version" +import ( + "runtime/debug" + "time" +) + // Variables populated at build time. var ( - Version = "dev" - Commit = "HEAD" - BuildDate = "undefined" + Version = "Development Version" + Commit = getCommit() + BuildDate = getBuildDate() ) + +func getCommit() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + return setting.Value[:8] // Short commit hash + } + } + } + return "HEAD" +} + +func getBuildDate() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.time" { + return setting.Value + } + } + } + return time.Now().Format(time.RFC3339) +}