From 1cb398fe83f0cc3c7630ef5a14637642c008d317 Mon Sep 17 00:00:00 2001 From: Mikhail Chusavitin Date: Fri, 3 Apr 2026 10:08:00 +0300 Subject: [PATCH] Show tag version at top of sidebar --- audit/Makefile | 6 ++++-- audit/cmd/bee/main.go | 26 +------------------------- audit/cmd/bee/main_test.go | 12 ++++++++++++ audit/internal/webui/pages.go | 9 +++++---- audit/internal/webui/server_test.go | 12 +++++++++--- audit/scripts/resolve-version.sh | 22 ++++++++++++++++++++++ 6 files changed, 53 insertions(+), 34 deletions(-) create mode 100755 audit/scripts/resolve-version.sh diff --git a/audit/Makefile b/audit/Makefile index 33038eb..cc0e97f 100644 --- a/audit/Makefile +++ b/audit/Makefile @@ -1,5 +1,7 @@ LISTEN ?= :8080 AUDIT_PATH ?= +VERSION ?= $(shell sh ./scripts/resolve-version.sh) +GO_LDFLAGS := -X main.Version=$(VERSION) RUN_ARGS := web --listen $(LISTEN) ifneq ($(AUDIT_PATH),) @@ -9,10 +11,10 @@ endif .PHONY: run build test run: - go run ./cmd/bee $(RUN_ARGS) + go run -ldflags "$(GO_LDFLAGS)" ./cmd/bee $(RUN_ARGS) build: - go build -o bee ./cmd/bee + go build -ldflags "$(GO_LDFLAGS)" -o bee ./cmd/bee test: go test ./... diff --git a/audit/cmd/bee/main.go b/audit/cmd/bee/main.go index dfd2279..f6b3856 100644 --- a/audit/cmd/bee/main.go +++ b/audit/cmd/bee/main.go @@ -7,7 +7,6 @@ import ( "io" "log/slog" "os" - "runtime/debug" "strings" "bee/audit/internal/app" @@ -21,30 +20,7 @@ var Version = "dev" func buildLabel() string { label := strings.TrimSpace(Version) if label == "" { - label = "dev" - } - if info, ok := debug.ReadBuildInfo(); ok { - var revision string - var modified bool - for _, setting := range info.Settings { - switch setting.Key { - case "vcs.revision": - revision = setting.Value - case "vcs.modified": - modified = setting.Value == "true" - } - } - if revision != "" { - short := revision - if len(short) > 12 { - short = short[:12] - } - label += " (" + short - if modified { - label += "+" - } - label += ")" - } + return "dev" } return label } diff --git a/audit/cmd/bee/main_test.go b/audit/cmd/bee/main_test.go index 8493200..dfa6d3f 100644 --- a/audit/cmd/bee/main_test.go +++ b/audit/cmd/bee/main_test.go @@ -62,6 +62,18 @@ func TestRunVersion(t *testing.T) { } } +func TestBuildLabelUsesVersionAsIs(t *testing.T) { + t.Parallel() + + old := Version + Version = "1.2.3" + t.Cleanup(func() { Version = old }) + + if got := buildLabel(); got != "1.2.3" { + t.Fatalf("buildLabel=%q want %q", got, "1.2.3") + } +} + func TestRunExportRequiresTarget(t *testing.T) { t.Parallel() diff --git a/audit/internal/webui/pages.go b/audit/internal/webui/pages.go index 8744e48..beffa0c 100644 --- a/audit/internal/webui/pages.go +++ b/audit/internal/webui/pages.go @@ -29,6 +29,7 @@ a{color:var(--accent);text-decoration:none} .sidebar{width:210px;min-height:100vh;background:#1b1c1d;flex-shrink:0;display:flex;flex-direction:column} .sidebar-logo{padding:18px 16px 12px;font-size:18px;font-weight:700;color:#fff;letter-spacing:-.5px} .sidebar-logo span{color:rgba(255,255,255,.5);font-weight:400;font-size:12px;display:block;margin-top:2px} +.sidebar-version{padding:0 16px 14px;font-size:11px;color:rgba(255,255,255,.45)} .nav{flex:1} .nav-item{display:block;padding:10px 16px;color:rgba(255,255,255,.7);font-size:13px;border-left:3px solid transparent;transition:all .15s} .nav-item:hover{color:#fff;background:rgba(255,255,255,.08)} @@ -96,6 +97,10 @@ func layoutNav(active string, buildLabel string) string { var b strings.Builder b.WriteString(``) return b.String() } diff --git a/audit/internal/webui/server_test.go b/audit/internal/webui/server_test.go index 9243d25..52335e6 100644 --- a/audit/internal/webui/server_test.go +++ b/audit/internal/webui/server_test.go @@ -275,9 +275,10 @@ func TestRootRendersDashboard(t *testing.T) { } handler := NewHandler(HandlerOptions{ - Title: "Bee Hardware Audit", - AuditPath: path, - ExportDir: exportDir, + Title: "Bee Hardware Audit", + BuildLabel: "1.2.3", + AuditPath: path, + ExportDir: exportDir, }) first := httptest.NewRecorder() @@ -292,6 +293,11 @@ func TestRootRendersDashboard(t *testing.T) { if !strings.Contains(first.Body.String(), `/viewer`) { t.Fatalf("first body missing viewer link: %s", first.Body.String()) } + versionIdx := strings.Index(first.Body.String(), `Version 1.2.3`) + navIdx := strings.Index(first.Body.String(), `href="/"`) + if versionIdx == -1 || navIdx == -1 || versionIdx > navIdx { + t.Fatalf("version should render near top of sidebar before nav links: %s", first.Body.String()) + } if got := first.Header().Get("Cache-Control"); got != "no-store" { t.Fatalf("first cache-control=%q", got) } diff --git a/audit/scripts/resolve-version.sh b/audit/scripts/resolve-version.sh new file mode 100755 index 0000000..d219a50 --- /dev/null +++ b/audit/scripts/resolve-version.sh @@ -0,0 +1,22 @@ +#!/bin/sh +set -eu + +tag="$(git describe --tags --match 'audit/v*' --abbrev=7 --dirty 2>/dev/null || true)" +if [ -z "${tag}" ]; then + tag="$(git describe --tags --match 'v[0-9]*' --abbrev=7 --dirty 2>/dev/null || true)" +fi + +case "${tag}" in + audit/v*) + printf '%s\n' "${tag#audit/v}" + ;; + v*) + printf '%s\n' "${tag#v}" + ;; + "") + printf 'dev\n' + ;; + *) + printf '%s\n' "${tag}" + ;; +esac