mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-02 04:16:38 +08:00
fix: embed release version in system update status
This commit is contained in:
+18
-2
@@ -18,6 +18,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@@ -33,6 +34,20 @@ import (
|
||||
// version is overwritten at build time via -ldflags="-X main.version=...".
|
||||
var version = "dev"
|
||||
|
||||
func effectiveVersion(buildVersion string) string {
|
||||
buildVersion = strings.TrimSpace(buildVersion)
|
||||
if buildVersion != "" && buildVersion != "dev" {
|
||||
return buildVersion
|
||||
}
|
||||
if envVersion := strings.TrimSpace(os.Getenv("MEDIASTATION_VERSION")); envVersion != "" {
|
||||
return envVersion
|
||||
}
|
||||
if buildVersion == "" {
|
||||
return "dev"
|
||||
}
|
||||
return buildVersion
|
||||
}
|
||||
|
||||
func main() {
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
@@ -47,8 +62,9 @@ func main() {
|
||||
}
|
||||
defer func() { _ = logger.Sync() }()
|
||||
|
||||
appVersion := effectiveVersion(version)
|
||||
logger.Info("starting MediaStationGo",
|
||||
zap.String("version", version),
|
||||
zap.String("version", appVersion),
|
||||
zap.Int("port", cfg.App.Port),
|
||||
zap.String("data_dir", cfg.App.DataDir),
|
||||
)
|
||||
@@ -77,7 +93,7 @@ func main() {
|
||||
repos := repository.New(db)
|
||||
service.ApplyRuntimeSettings(context.Background(), cfg, repos, logger)
|
||||
applyCPUThreadLimit(cfg, logger)
|
||||
services := service.NewWithVersion(cfg, logger, repos, version)
|
||||
services := service.NewWithVersion(cfg, logger, repos, appVersion)
|
||||
|
||||
if repaired, err := services.RepairCloudPathMetadata(context.Background()); err != nil {
|
||||
logger.Warn("cloud path metadata repair failed", zap.Error(err))
|
||||
|
||||
@@ -11,6 +11,30 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestEffectiveVersionPrefersBuildVersion(t *testing.T) {
|
||||
t.Setenv("MEDIASTATION_VERSION", "MediaStationGo-v0.1.15")
|
||||
|
||||
if got := effectiveVersion("MediaStationGo-v0.1.16"); got != "MediaStationGo-v0.1.16" {
|
||||
t.Fatalf("effectiveVersion = %q, want MediaStationGo-v0.1.16", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEffectiveVersionUsesEnvWhenBuildVersionIsDev(t *testing.T) {
|
||||
t.Setenv("MEDIASTATION_VERSION", " MediaStationGo-v0.1.16 ")
|
||||
|
||||
if got := effectiveVersion("dev"); got != "MediaStationGo-v0.1.16" {
|
||||
t.Fatalf("effectiveVersion = %q, want MediaStationGo-v0.1.16", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEffectiveVersionDefaultsToDev(t *testing.T) {
|
||||
t.Setenv("MEDIASTATION_VERSION", "")
|
||||
|
||||
if got := effectiveVersion(""); got != "dev" {
|
||||
t.Fatalf("effectiveVersion = %q, want dev", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeSPANoCachesIndexAndServesRoutes(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
webDir := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user