mirror of
https://github.com/miniflux/v2.git
synced 2025-08-26 18:21:01 +00:00
feat(version): use Golang's builtin vcs feature to get commit and build date
This commit is contained in:
parent
88d9682f5f
commit
c1af510ead
2 changed files with 42 additions and 17 deletions
26
Makefile
26
Makefile
|
@ -1,9 +1,7 @@
|
||||||
APP := miniflux
|
APP := miniflux
|
||||||
DOCKER_IMAGE := miniflux/miniflux
|
DOCKER_IMAGE := miniflux/miniflux
|
||||||
VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null)
|
VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null)
|
||||||
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null)
|
LD_FLAGS := "-s -w -X 'miniflux.app/v2/internal/version.Version=$(VERSION)'"
|
||||||
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)'"
|
|
||||||
PKG_LIST := $(shell go list ./... | grep -v /vendor/)
|
PKG_LIST := $(shell go list ./... | grep -v /vendor/)
|
||||||
DB_URL := postgres://postgres:postgres@localhost/miniflux_test?sslmode=disable
|
DB_URL := postgres://postgres:postgres@localhost/miniflux_test?sslmode=disable
|
||||||
DOCKER_PLATFORM := amd64
|
DOCKER_PLATFORM := amd64
|
||||||
|
@ -40,45 +38,45 @@ export PGPASSWORD := postgres
|
||||||
debian-packages
|
debian-packages
|
||||||
|
|
||||||
miniflux:
|
miniflux:
|
||||||
@ go build -buildmode=pie -ldflags=$(LD_FLAGS) -o $(APP) main.go
|
@ go build -buildmode=pie -ldflags=$(LD_FLAGS) -o $(APP)
|
||||||
|
|
||||||
miniflux-no-pie:
|
miniflux-no-pie:
|
||||||
@ go build -ldflags=$(LD_FLAGS) -o $(APP) main.go
|
@ go build -ldflags=$(LD_FLAGS) -o $(APP)
|
||||||
|
|
||||||
linux-amd64:
|
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
|
@ sha256sum $(APP)-$@ > $(APP)-$@.sha256
|
||||||
|
|
||||||
linux-arm64:
|
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
|
@ sha256sum $(APP)-$@ > $(APP)-$@.sha256
|
||||||
|
|
||||||
linux-armv7:
|
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
|
@ sha256sum $(APP)-$@ > $(APP)-$@.sha256
|
||||||
|
|
||||||
linux-armv6:
|
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
|
@ sha256sum $(APP)-$@ > $(APP)-$@.sha256
|
||||||
|
|
||||||
linux-armv5:
|
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
|
@ sha256sum $(APP)-$@ > $(APP)-$@.sha256
|
||||||
|
|
||||||
darwin-amd64:
|
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
|
@ sha256sum $(APP)-$@ > $(APP)-$@.sha256
|
||||||
|
|
||||||
darwin-arm64:
|
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
|
@ sha256sum $(APP)-$@ > $(APP)-$@.sha256
|
||||||
|
|
||||||
freebsd-amd64:
|
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
|
@ sha256sum $(APP)-$@ > $(APP)-$@.sha256
|
||||||
|
|
||||||
openbsd-amd64:
|
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
|
@ sha256sum $(APP)-$@ > $(APP)-$@.sha256
|
||||||
|
|
||||||
build: linux-amd64 linux-arm64 linux-armv7 linux-armv6 linux-armv5 darwin-amd64 darwin-arm64 freebsd-amd64 openbsd-amd64
|
build: linux-amd64 linux-arm64 linux-armv7 linux-armv6 linux-armv5 darwin-amd64 darwin-arm64 freebsd-amd64 openbsd-amd64
|
||||||
|
|
|
@ -3,9 +3,36 @@
|
||||||
|
|
||||||
package version // import "miniflux.app/v2/internal/version"
|
package version // import "miniflux.app/v2/internal/version"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime/debug"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// Variables populated at build time.
|
// Variables populated at build time.
|
||||||
var (
|
var (
|
||||||
Version = "dev"
|
Version = "Development Version"
|
||||||
Commit = "HEAD"
|
Commit = getCommit()
|
||||||
BuildDate = "undefined"
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue