build: add versioning (2026.6.0001) with ldflags and /api/version endpoint

This commit is contained in:
Claus Lohmar 2026-06-14 15:09:02 +00:00
parent f66bf88d47
commit 93104b24d6
4 changed files with 47 additions and 10 deletions

1
VERSION Normal file
View file

@ -0,0 +1 @@
2026.6.0001

View file

@ -186,17 +186,26 @@ fi
if [ "$SKIP_BUILD" = false ] && [ "$CONFIG_ONLY" = false ]; then if [ "$SKIP_BUILD" = false ] && [ "$CONFIG_ONLY" = false ]; then
info "Building Next Workspace core..." 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 cd "$REPO_DIR/src"
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 for smaller binary # Run tests first
go build -o "$REPO_DIR/app/core" -ldflags="-s -w" . info "Running tests..."
success "Core binary built: app/core" 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 if [ "$BUILD_ONLY" = true ]; then
success "Build complete (--build-only, skipping install)" success "Build complete (--build-only, skipping install)"

View file

@ -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,
}
}

View file

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"encoding/json"
"flag" "flag"
"fmt" "fmt"
"log/slog" "log/slog"
@ -16,6 +17,7 @@ import (
"git.lohmar.co.uk/lexton-it/NextWks/core/config" "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/db"
"git.lohmar.co.uk/lexton-it/NextWks/core/ui" "git.lohmar.co.uk/lexton-it/NextWks/core/ui"
"git.lohmar.co.uk/lexton-it/NextWks/core/version"
) )
func main() { func main() {
@ -25,7 +27,7 @@ func main() {
configPath := flag.String("config", "./config.yaml", "path to configuration file") configPath := flag.String("config", "./config.yaml", "path to configuration file")
flag.Parse() flag.Parse()
logger.Info("starting Next Workspace (NextWks)", "config", *configPath) logger.Info("starting Next Workspace (NextWks)", "version", version.Version, "config", *configPath)
// Load configuration // Load configuration
cfg, err := config.Load(*configPath) cfg, err := config.Load(*configPath)
@ -106,6 +108,10 @@ func main() {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"status":"ok"}`)) 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) --- // --- OIDC auth routes (public) ---
mux.HandleFunc("GET /auth/login", oidcHandler.LoginRedirect) mux.HandleFunc("GET /auth/login", oidcHandler.LoginRedirect)