From eb756544039fe217c6774733a9268c1b34bf474e Mon Sep 17 00:00:00 2001 From: Ryan Hamamura <58859899+ryanhamamura@users.noreply.github.com> Date: Tue, 3 Mar 2026 09:23:37 -1000 Subject: [PATCH] feat: display app version in UI footer - Add version package with build-time variables - Inject version via ldflags in Dockerfile using git describe - Show version in footer on every page - Log version and commit on server startup --- .gitea/workflows/deploy.yml | 8 +++++++- Dockerfile | 6 +++++- docker-compose.yml | 6 +++++- features/common/layouts/base.templ | 8 +++++++- main.go | 3 ++- version/version.go | 10 ++++++++++ 6 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 version/version.go diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 9aa9673..4d810a2 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -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 diff --git a/Dockerfile b/Dockerfile index 0b62d6c..cd0b49a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 821ee2e..7929878 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,10 @@ services: games: - build: . + build: + context: . + args: + VERSION: ${VERSION:-dev} + COMMIT: ${COMMIT:-unknown} container_name: games restart: unless-stopped ports: diff --git a/features/common/layouts/base.templ b/features/common/layouts/base.templ index 86d563a..5029e7f 100644 --- a/features/common/layouts/base.templ +++ b/features/common/layouts/base.templ @@ -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) { @@ -16,6 +19,9 @@ templ Base(title string) {
} { children... } +