Skip to content

Commit 322a825

Browse files
committed
feat: Add git versioning information on UI
* Include a VITE_VERSION derived from git describe. * Include frontend sidebar information showing VITE_VERSION. Closes #1611 Signed-off-by: Alan Peixinho <alan.peixinho@profusion.mobi>
1 parent b9f9d1e commit 322a825

6 files changed

Lines changed: 34 additions & 0 deletions

File tree

.github/workflows/deploy-containers.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,17 @@ jobs:
5757
digest: ${{ steps.build.outputs.digest }}
5858
steps:
5959
- uses: actions/checkout@v4
60+
with:
61+
fetch-depth: 0
6062

6163
- name: Compute image prefix
6264
id: meta
6365
run: echo "prefix=${REGISTRY}/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT"
6466

67+
- name: Compute app version
68+
id: version
69+
run: echo "value=$(git describe --tags --always)" >> "$GITHUB_OUTPUT"
70+
6571
- name: Log in to GHCR
6672
uses: docker/login-action@v3
6773
with:
@@ -79,6 +85,8 @@ jobs:
7985
context: .
8086
file: ./dashboard/Dockerfile
8187
push: true
88+
build-args: |
89+
VITE_APP_VERSION=${{ steps.version.outputs.value }}
8290
tags: |
8391
${{ steps.meta.outputs.prefix }}/dashboard-frontend:latest
8492
${{ steps.meta.outputs.prefix }}/dashboard-frontend:${{ github.sha }}

.github/workflows/deploy-staging.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ jobs:
6767
cp ~/.env-staging dashboard-staging/.env &&
6868
cd dashboard-staging &&
6969
git checkout ${GITHUB_SHA} &&
70+
git fetch --tags --depth 1 || true &&
71+
export APP_VERSION=\$(git describe --tags --always) &&
7072
docker compose down &&
7173
docker compose build --no-cache &&
7274
docker compose up -d

dashboard/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ RUN npm install -g pnpm@10.33.3 && pnpm install --frozen-lockfile
88

99
COPY dashboard/. ./
1010

11+
ARG VITE_APP_VERSION
12+
ENV VITE_APP_VERSION=$VITE_APP_VERSION
13+
1114
RUN pnpm build
1215

1316
# Stage 2: Copy the static files from the builder stage

dashboard/src/components/SideMenu/SideMenuContent.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ const SideMenuContent = ({
124124
<div className="flex w-full flex-col space-y-0">
125125
{dashboardElements}
126126
</div>
127+
<Separator className="bg-on-secondary-10 my-4" />
128+
<span className="block w-full px-4 text-xs break-words text-white/40">
129+
{import.meta.env.VITE_APP_VERSION}
130+
</span>
127131
</NavigationMenuList>
128132
</NavigationMenu>
129133
);

dashboard/vite.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import path from 'path';
2+
import { execSync } from 'node:child_process';
3+
24
import { defineConfig } from 'vite';
35
import react from '@vitejs/plugin-react';
46
import tsconfigPaths from 'vite-tsconfig-paths';
57
import tailwindcss from '@tailwindcss/vite';
68

79
import { TanStackRouterVite } from '@tanstack/router-plugin/vite';
810

11+
const appVersion =
12+
process.env.VITE_APP_VERSION ||
13+
((): string => {
14+
try {
15+
return execSync('git describe --tags --always --dirty').toString().trim();
16+
} catch {
17+
return 'unknown';
18+
}
19+
})();
20+
921
// https://vitejs.dev/config/
1022
export default defineConfig({
1123
plugins: [tailwindcss(), tsconfigPaths(), react(), TanStackRouterVite()],
24+
define: {
25+
'import.meta.env.VITE_APP_VERSION': JSON.stringify(appVersion),
26+
},
1227
resolve: {
1328
alias: {
1429
'@': path.resolve(__dirname, './src'),

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ services:
114114
build:
115115
context: .
116116
dockerfile: ./dashboard/Dockerfile
117+
args:
118+
VITE_APP_VERSION: ${APP_VERSION:-}
117119
image: ${IMAGE_REGISTRY:-ghcr.io}/${IMAGE_REPOSITORY:-local}/dashboard-frontend:${IMAGE_TAG:-latest}
118120
volumes:
119121
- static-data:/data/static

0 commit comments

Comments
 (0)