feat(frontend): inject commit ID into frontend build for version tracking
- Added a new build argument `COMMIT_ID_ARG` to pass the commit ID during the Docker build process. - Updated the Dockerfile to set an environment variable `VITE_FRONTEND_COMMIT` with the commit ID. - Enhanced the Vite configuration to resolve the frontend commit ID from the environment or Git. - Modified the SystemInfo component to display the frontend commit ID in the UI. - Implemented a version info preparation step in the GitHub Actions workflow to capture the commit ID.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import { resolve, dirname } from 'node:path'
|
||||
import { existsSync } from 'node:fs'
|
||||
import { execSync } from 'node:child_process'
|
||||
import { createRequire } from 'node:module'
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
@@ -11,6 +12,22 @@ const require = createRequire(import.meta.url)
|
||||
|
||||
const pkg = require('./package.json') as { version?: string }
|
||||
const FRONTEND_VERSION = pkg.version ?? 'unknown'
|
||||
|
||||
function resolveFrontendCommit(): string {
|
||||
const fromEnv = process.env.VITE_FRONTEND_COMMIT || process.env.GITHUB_SHA
|
||||
if (fromEnv) {
|
||||
return fromEnv.slice(0, 7)
|
||||
}
|
||||
try {
|
||||
return execSync('git rev-parse --short HEAD', { stdio: ['ignore', 'pipe', 'ignore'] })
|
||||
.toString()
|
||||
.trim()
|
||||
} catch {
|
||||
return 'unknown'
|
||||
}
|
||||
}
|
||||
|
||||
const FRONTEND_COMMIT = resolveFrontendCommit()
|
||||
const DEV_PROXY_TARGET =
|
||||
process.env.VITE_DEV_PROXY_TARGET ||
|
||||
process.env.FRONTEND_BACKEND_URL ||
|
||||
@@ -34,6 +51,7 @@ function resolveVueOfficePptxEntry(): string {
|
||||
export default defineConfig({
|
||||
define: {
|
||||
__FRONTEND_VERSION__: JSON.stringify(FRONTEND_VERSION),
|
||||
__FRONTEND_COMMIT__: JSON.stringify(FRONTEND_COMMIT),
|
||||
},
|
||||
plugins: [
|
||||
vue(),
|
||||
|
||||
Reference in New Issue
Block a user