Skip to content

Commit 2526da4

Browse files
committed
Fix build version environment variables for Vite
- Change REACT_APP_* to VITE_APP_* prefix (required by Vite) - Update Dockerfile to use VITE_APP_VERSION, VITE_APP_BUILD_TIME, VITE_APP_COMMIT_SHA - Update GitHub Actions workflow with correct environment variable names - Add fallback to package.json version (0.1.0) if env vars not available - Improve timestamp formatting from ISO string - Add debug logging for environment variables This fixes the 'vunknown' issue in the build version indicator. The version should now show: 'v1.0.0 • abc1234 • 2025-09-20 14:04'
1 parent 7459184 commit 2526da4

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

.github/workflows/docker-build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ jobs:
5959
tags: ${{ steps.meta.outputs.tags }}
6060
labels: ${{ steps.meta.outputs.labels }}
6161
build-args: |
62-
REACT_APP_VERSION=1.0.0
63-
REACT_APP_BUILD_TIME=${{ github.event.head_commit.timestamp }}
64-
REACT_APP_COMMIT_SHA=${{ github.sha }}
62+
VITE_APP_VERSION=1.0.0
63+
VITE_APP_BUILD_TIME=${{ github.event.head_commit.timestamp }}
64+
VITE_APP_COMMIT_SHA=${{ github.sha }}
6565
cache-from: type=gha
6666
cache-to: type=gha,mode=max
6767
platforms: linux/amd64,linux/arm64

editor/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ FROM node:18-alpine AS build
33
WORKDIR /app
44

55
# Build arguments for version info
6-
ARG REACT_APP_VERSION=1.0.0
7-
ARG REACT_APP_BUILD_TIME
8-
ARG REACT_APP_COMMIT_SHA
9-
10-
# Set environment variables for the build
11-
ENV REACT_APP_VERSION=$REACT_APP_VERSION
12-
ENV REACT_APP_BUILD_TIME=$REACT_APP_BUILD_TIME
13-
ENV REACT_APP_COMMIT_SHA=$REACT_APP_COMMIT_SHA
6+
ARG VITE_APP_VERSION=1.0.0
7+
ARG VITE_APP_BUILD_TIME
8+
ARG VITE_APP_COMMIT_SHA
9+
10+
# Set environment variables for the build (Vite requires VITE_ prefix)
11+
ENV VITE_APP_VERSION=$VITE_APP_VERSION
12+
ENV VITE_APP_BUILD_TIME=$VITE_APP_BUILD_TIME
13+
ENV VITE_APP_COMMIT_SHA=$VITE_APP_COMMIT_SHA
1414

1515
# Copy package files first for better Docker layer caching
1616
COPY package.json package-lock.json ./

editor/src/utils/buildInfo.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,35 @@ export const getBuildInfo = (): BuildInfo => {
1414
};
1515
}
1616

17-
// In production, these will be replaced by build process
17+
// Debug: log available environment variables in development/console
18+
if (import.meta.env.DEV) {
19+
console.log('Available Vite env vars:', {
20+
VITE_APP_VERSION: import.meta.env.VITE_APP_VERSION,
21+
VITE_APP_BUILD_TIME: import.meta.env.VITE_APP_BUILD_TIME,
22+
VITE_APP_COMMIT_SHA: import.meta.env.VITE_APP_COMMIT_SHA,
23+
});
24+
}
25+
26+
// In production, use Vite environment variables (VITE_ prefix required)
27+
// Fallback to package version if environment variable not available
28+
const envVersion = import.meta.env.VITE_APP_VERSION;
29+
const version = envVersion && envVersion !== 'undefined' ? envVersion : '0.1.0';
30+
const buildTime = import.meta.env.VITE_APP_BUILD_TIME;
31+
const commitSha = import.meta.env.VITE_APP_COMMIT_SHA;
32+
33+
// Format the build time if available
34+
let timestamp: string;
35+
if (buildTime) {
36+
// Convert ISO timestamp to readable format
37+
timestamp = new Date(buildTime).toISOString().slice(0, 16).replace('T', ' ');
38+
} else {
39+
timestamp = new Date().toISOString().slice(0, 16).replace('T', ' ');
40+
}
41+
1842
return {
19-
version: process.env.REACT_APP_VERSION || 'unknown',
20-
timestamp: process.env.REACT_APP_BUILD_TIME || new Date().toISOString().slice(0, 16).replace('T', ' '),
21-
commit: process.env.REACT_APP_COMMIT_SHA?.slice(0, 7) || undefined,
43+
version,
44+
timestamp,
45+
commit: commitSha?.slice(0, 7) || undefined,
2246
};
2347
};
2448

0 commit comments

Comments
 (0)