Add version display in UI footer #8

Merged
ryan merged 1 commits from feat/version-display into main 2026-03-03 19:41:59 +00:00
6 changed files with 36 additions and 5 deletions
Showing only changes of commit eb75654403 - Show all commits

View File

@@ -48,6 +48,8 @@ jobs:
runs-on: games
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history for git describe
- name: Sync to deploy directory
run: |
@@ -59,4 +61,8 @@ jobs:
mkdir -p $DEPLOY_DIR/data
- name: Rebuild and restart
run: cd $DEPLOY_DIR && docker compose up -d --build --remove-orphans
run: |
cd $DEPLOY_DIR
VERSION=$(git describe --tags --always)
COMMIT=$(git rev-parse --short HEAD)
VERSION=$VERSION COMMIT=$COMMIT docker compose up -d --build --remove-orphans

View File

@@ -1,5 +1,8 @@
FROM docker.io/golang:1.25.4-alpine AS build
ARG VERSION=dev
ARG COMMIT=unknown
RUN apk add --no-cache upx
WORKDIR /src
@@ -10,7 +13,8 @@ COPY . .
RUN go tool templ generate
RUN go tool gotailwind -i assets/css/input.css -o assets/css/output.css --minify
RUN --mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 go build -ldflags="-s" -o /bin/games .
MODULE=$(head -1 go.mod | awk '{print $2}') && \
CGO_ENABLED=0 go build -ldflags="-s -X $MODULE/version.Version=$VERSION -X $MODULE/version.Commit=$COMMIT" -o /bin/games .
RUN upx -9 -k /bin/games
FROM scratch

View File

@@ -1,6 +1,10 @@
services:
games:
build: .
build:
context: .
args:
VERSION: ${VERSION:-dev}
COMMIT: ${COMMIT:-unknown}
container_name: games
restart: unless-stopped
ports:

View File

@@ -1,6 +1,9 @@
package layouts
import "github.com/ryanhamamura/games/config"
import (
"github.com/ryanhamamura/games/config"
"github.com/ryanhamamura/games/version"
)
templ Base(title string) {
<!DOCTYPE html>
@@ -16,6 +19,9 @@ templ Base(title string) {
<div data-init="@get('/reload', {retryMaxCount: 1000, retryInterval:20, retryMaxWaitMs:200})"></div>
}
{ children... }
<footer class="fixed bottom-1 right-2 text-xs text-gray-500">
{ version.Version }
</footer>
</body>
</html>
}

View File

@@ -20,6 +20,7 @@ import (
"github.com/ryanhamamura/games/router"
"github.com/ryanhamamura/games/sessions"
"github.com/ryanhamamura/games/snake"
"github.com/ryanhamamura/games/version"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
@@ -45,7 +46,7 @@ func main() {
func run(ctx context.Context) error {
cfg := config.Global
addr := fmt.Sprintf("%s:%s", cfg.Host, cfg.Port)
slog.Info("server starting", "addr", addr)
slog.Info("server starting", "addr", addr, "version", version.Version, "commit", version.Commit)
defer slog.Info("server shutdown complete")
eg, egctx := errgroup.WithContext(ctx)

10
version/version.go Normal file
View File

@@ -0,0 +1,10 @@
// Package version holds build-time version information injected via ldflags.
package version
// Version and Commit are set at build time via:
//
// -ldflags "-X github.com/ryanhamamura/games/version.Version=... -X github.com/ryanhamamura/games/version.Commit=..."
var (
Version = "dev"
Commit = "unknown"
)