build: add versioning (2026.6.0001) with ldflags and /api/version endpoint
This commit is contained in:
parent
f66bf88d47
commit
93104b24d6
4 changed files with 47 additions and 10 deletions
1
VERSION
Normal file
1
VERSION
Normal file
|
|
@ -0,0 +1 @@
|
|||
2026.6.0001
|
||||
15
install.sh
15
install.sh
|
|
@ -186,6 +186,11 @@ fi
|
|||
if [ "$SKIP_BUILD" = false ] && [ "$CONFIG_ONLY" = false ]; then
|
||||
info "Building Next Workspace core..."
|
||||
|
||||
# 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")
|
||||
|
||||
cd "$REPO_DIR/src"
|
||||
|
||||
# Run tests first
|
||||
|
|
@ -194,9 +199,13 @@ if [ "$SKIP_BUILD" = false ] && [ "$CONFIG_ONLY" = false ]; then
|
|||
warn "Some tests failed — continuing build anyway"
|
||||
fi
|
||||
|
||||
# Build with stripped symbols for smaller binary
|
||||
go build -o "$REPO_DIR/app/core" -ldflags="-s -w" .
|
||||
success "Core binary built: app/core"
|
||||
# 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)"
|
||||
|
|
|
|||
21
src/core/version/version.go
Normal file
21
src/core/version/version.go
Normal 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,
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue