fix version display
This commit is contained in:
parent
7a19a15365
commit
6abccc5429
4 changed files with 45 additions and 10 deletions
5
Makefile
5
Makefile
|
@ -42,8 +42,9 @@ clean:
|
|||
rm -rf dist
|
||||
|
||||
dist/%: ${CMD_DIR}/% FORCE
|
||||
go build \
|
||||
-ldflags "-X ${MODULE_PATH}/internal/version.BuildDate=$(BUILDDATE)" \
|
||||
go build -buildvcs\
|
||||
-ldflags "-X ${MODULE_PATH}/internal/version.tagVersion=$(VERSION) \
|
||||
-X ${MODULE_PATH}/internal/version.buildDate=$(BUILDDATE)" \
|
||||
-o $@ ${MODULE_PATH}/$<
|
||||
|
||||
.PHONY: build clean
|
||||
|
|
|
@ -3,13 +3,13 @@ package funcmap
|
|||
import "github.com/eternal-flame-AD/yoake/internal/version"
|
||||
|
||||
type V struct {
|
||||
Version string
|
||||
BuildDate string
|
||||
Version string
|
||||
Date string
|
||||
}
|
||||
|
||||
func Version() (*V, error) {
|
||||
return &V{
|
||||
Version: version.Version,
|
||||
BuildDate: version.BuildDate,
|
||||
Version: version.Version,
|
||||
Date: version.Date,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -1,14 +1,48 @@
|
|||
package version
|
||||
|
||||
import "runtime/debug"
|
||||
import (
|
||||
"runtime/debug"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
tagVersion = ""
|
||||
buildDate = "unknown"
|
||||
|
||||
Date = "unknown"
|
||||
Version = func() string {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return "unknown"
|
||||
}
|
||||
return info.Main.Version
|
||||
|
||||
var vcsRevision string
|
||||
var vcsTime time.Time
|
||||
var vcsModified bool
|
||||
for _, setting := range info.Settings {
|
||||
switch setting.Key {
|
||||
case "vcs.revision":
|
||||
vcsRevision = setting.Value
|
||||
case "vcs.time":
|
||||
vcsTime, _ = time.Parse(time.RFC3339, setting.Value)
|
||||
case "vcs.modified":
|
||||
vcsModified = setting.Value != "false"
|
||||
}
|
||||
}
|
||||
if tagVersion != "" {
|
||||
vcsRevision = tagVersion
|
||||
}
|
||||
|
||||
if vcsModified {
|
||||
Date = buildDate
|
||||
return vcsRevision + "+devel"
|
||||
} else {
|
||||
Date = buildDate
|
||||
if !vcsTime.IsZero() {
|
||||
Date = vcsTime.Format("2006-01-02T15:04Z07:00")
|
||||
}
|
||||
return vcsRevision
|
||||
}
|
||||
|
||||
}()
|
||||
BuildDate = "unknown"
|
||||
)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">
|
||||
<a class="navbar-brand col-md-3 col-lg-2 me-0 px-3 fs-6" href="#">
|
||||
{{- (call .Config).WebRoot.SiteName -}}
|
||||
<small class="fw-lighter text-muted px-2">{{ $version.Version }} - {{ $version.BuildDate }}</small>
|
||||
<small class="fw-lighter text-muted px-2">{{ $version.Version }} - {{ $version.Date }}</small>
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler position-absolute d-md-none collapsed" type="button" data-bs-toggle="collapse"
|
||||
|
|
Loading…
Add table
Reference in a new issue