From 93104b24d6ac4e2f35e2cbd5a7fd7aed5e1fb12d Mon Sep 17 00:00:00 2001 From: cclohmar Date: Sun, 14 Jun 2026 15:09:02 +0000 Subject: [PATCH] build: add versioning (2026.6.0001) with ldflags and /api/version endpoint --- VERSION | 1 + install.sh | 27 ++++++++++++++++++--------- src/core/version/version.go | 21 +++++++++++++++++++++ src/main.go | 8 +++++++- 4 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 VERSION create mode 100644 src/core/version/version.go diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..76447f6 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2026.6.0001 diff --git a/install.sh b/install.sh index b6ea670..3118cc6 100755 --- a/install.sh +++ b/install.sh @@ -186,17 +186,26 @@ fi if [ "$SKIP_BUILD" = false ] && [ "$CONFIG_ONLY" = false ]; then info "Building Next Workspace core..." - cd "$REPO_DIR/src" + # Build with version info from ldflags + VERSION=$(cat "$REPO_DIR/VERSION" 2>/dev/null || echo "dev") + BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + COMMIT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") - # Run tests first - info "Running tests..." - if ! go test -count=1 ./... 2>&1 | tail -1; then - warn "Some tests failed — continuing build anyway" - fi + cd "$REPO_DIR/src" - # Build with stripped symbols for smaller binary - go build -o "$REPO_DIR/app/core" -ldflags="-s -w" . - success "Core binary built: app/core" + # Run tests first + info "Running tests..." + if ! go test -count=1 ./... 2>&1 | tail -1; then + warn "Some tests failed — continuing build anyway" + fi + + # Build with stripped symbols and version info + go build -ldflags="-s -w \ + -X git.lohmar.co.uk/lexton-it/NextWks/core/version.Version=${VERSION} \ + -X git.lohmar.co.uk/lexton-it/NextWks/core/version.BuildTime=${BUILD_TIME} \ + -X git.lohmar.co.uk/lexton-it/NextWks/core/version.CommitSHA=${COMMIT_SHA}" \ + -o "$REPO_DIR/app/core" . + success "Core binary built: app/core (${VERSION})" if [ "$BUILD_ONLY" = true ]; then success "Build complete (--build-only, skipping install)" diff --git a/src/core/version/version.go b/src/core/version/version.go new file mode 100644 index 0000000..5cc19f3 --- /dev/null +++ b/src/core/version/version.go @@ -0,0 +1,21 @@ +package version + +var ( + // Version is set at build time via ldflags: -X git.lohmar.co.uk/lexton-it/NextWks/core/version.Version=2026.6.0001 + Version = "dev" + + // BuildTime is set at build time via ldflags. + BuildTime = "unknown" + + // CommitSHA is set at build time via ldflags. + CommitSHA = "unknown" +) + +// Info returns a formatted version info response. +func Info() map[string]string { + return map[string]string{ + "version": Version, + "build_time": BuildTime, + "commit": CommitSHA, + } +} diff --git a/src/main.go b/src/main.go index 1c1a077..b992ce3 100644 --- a/src/main.go +++ b/src/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "encoding/json" "flag" "fmt" "log/slog" @@ -16,6 +17,7 @@ import ( "git.lohmar.co.uk/lexton-it/NextWks/core/config" "git.lohmar.co.uk/lexton-it/NextWks/core/db" "git.lohmar.co.uk/lexton-it/NextWks/core/ui" + "git.lohmar.co.uk/lexton-it/NextWks/core/version" ) func main() { @@ -25,7 +27,7 @@ func main() { configPath := flag.String("config", "./config.yaml", "path to configuration file") flag.Parse() - logger.Info("starting Next Workspace (NextWks)", "config", *configPath) + logger.Info("starting Next Workspace (NextWks)", "version", version.Version, "config", *configPath) // Load configuration cfg, err := config.Load(*configPath) @@ -106,6 +108,10 @@ func main() { w.Header().Set("Content-Type", "application/json") w.Write([]byte(`{"status":"ok"}`)) }) + mux.HandleFunc("GET /api/version", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(version.Info()) + }) // --- OIDC auth routes (public) --- mux.HandleFunc("GET /auth/login", oidcHandler.LoginRedirect)