mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 23:24:01 +03:00
Use embedded buildinfo
This commit is contained in:
@@ -4,10 +4,8 @@ APP_NAME := $(IMAGE_NAME)
|
|||||||
|
|
||||||
GOLANGCI_LINT_VERSION := v1.44.2
|
GOLANGCI_LINT_VERSION := v1.44.2
|
||||||
|
|
||||||
VERSION_GO := $(shell go version)
|
VERSION := $(shell git describe --exact-match HEAD 2>/dev/null || git describe --tags --always)
|
||||||
VERSION_DATE := $(shell date -Ru)
|
COMMON_BUILD_FLAGS := -trimpath -mod=readonly -ldflags="-extldflags '-static' -s -w -X 'main.version=$(VERSION)'"
|
||||||
VERSION_TAG := $(shell git describe --tags --always)
|
|
||||||
COMMON_BUILD_FLAGS := -trimpath -mod=readonly -ldflags="-extldflags '-static' -s -w -X 'main.version=$(VERSION_TAG) ($(VERSION_GO)) [$(VERSION_DATE)]'"
|
|
||||||
|
|
||||||
FUZZ_FLAGS := -fuzztime=120s
|
FUZZ_FLAGS := -fuzztime=120s
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"runtime/debug"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/v2/internal/cli"
|
"github.com/9seconds/mtg/v2/internal/cli"
|
||||||
@@ -26,6 +29,32 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if buildInfo, ok := debug.ReadBuildInfo(); ok {
|
||||||
|
vcsCommit := "<no-commit>"
|
||||||
|
vcsDate := time.Now()
|
||||||
|
vcsDirty := ""
|
||||||
|
|
||||||
|
for _, setting := range buildInfo.Settings {
|
||||||
|
switch setting.Key {
|
||||||
|
case "vcs.time":
|
||||||
|
vcsDate, _ = time.Parse(time.RFC3339, setting.Value)
|
||||||
|
case "vcs.revision":
|
||||||
|
vcsCommit = setting.Value
|
||||||
|
case "vcs.modified":
|
||||||
|
if isDirty, _ := strconv.ParseBool(setting.Value); isDirty {
|
||||||
|
vcsDirty = " [dirty]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
version = fmt.Sprintf("%s (%s: %s on %s%s)",
|
||||||
|
version,
|
||||||
|
buildInfo.GoVersion,
|
||||||
|
vcsDate.Format(time.RFC3339),
|
||||||
|
vcsCommit,
|
||||||
|
vcsDirty)
|
||||||
|
}
|
||||||
|
|
||||||
cli := &cli.CLI{}
|
cli := &cli.CLI{}
|
||||||
ctx := kong.Parse(cli, kong.Vars{
|
ctx := kong.Parse(cli, kong.Vars{
|
||||||
"version": version,
|
"version": version,
|
||||||
|
|||||||
Reference in New Issue
Block a user