diff --git a/.github/workflows/dashboard-ci.yml b/.github/workflows/dashboard-ci.yml index 1ef2dab..a898726 100644 --- a/.github/workflows/dashboard-ci.yml +++ b/.github/workflows/dashboard-ci.yml @@ -55,6 +55,8 @@ jobs: working-directory: ./dashboard steps: - uses: actions/checkout@v4 + with: + fetch-depth: '0' - uses: pnpm/action-setup@v3 name: Install pnpm @@ -77,6 +79,21 @@ jobs: - name: 📥 Install deps run: pnpm install + - name: Set Git version for PRs + if: github.event_name == 'pull_request' + id: get_version + run: | + LATEST_TAG=${{ github.ref_name }} + LATEST_COMMIT=${{ github.sha }} + echo "VITE_LATEST_APP_VERSION=${LATEST_TAG}-${LATEST_COMMIT:0:7}" >> $GITHUB_ENV + + - name: Set Git version for main branch + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + id: get_version + run: | + LATEST_TAG=${{ github.ref_name }} + echo "VITE_LATEST_APP_VERSION=${LATEST_TAG}" >> $GITHUB_ENV + - name: Build Dashboard run: pnpm build --base '/dashboard/' diff --git a/Dockerfile b/Dockerfile index 62a18cd..e9511cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ WORKDIR /app COPY . /app RUN apt-get update -y \ - && apt-get install make gcc g++ python3-dev -y --no-install-recommends \ + && apt-get install make git gcc g++ python3-dev -y --no-install-recommends \ && pip install --no-cache-dir -r /app/requirements.txt \ && apt-get clean -y \ && apt-get remove g++ gcc python3-dev -y \ diff --git a/dashboard/src/components/page/index.tsx b/dashboard/src/components/page/index.tsx index cabbeae..383e2fd 100644 --- a/dashboard/src/components/page/index.tsx +++ b/dashboard/src/components/page/index.tsx @@ -10,7 +10,7 @@ interface PageProps extends PropsWithChildren { } export const Page: FC = ({ children }) => { return ( - +
{children}
diff --git a/dashboard/src/features/footer/index.tsx b/dashboard/src/features/footer/index.tsx index d73adbe..0df1006 100644 --- a/dashboard/src/features/footer/index.tsx +++ b/dashboard/src/features/footer/index.tsx @@ -1,9 +1,11 @@ -import packageJson from '@marzneshin/../package.json' assert { type: 'json' }; +import { Badge } from "@marzneshin/components"; export const DashboardFooter = () => { return (
- v{packageJson.version} Marzneshin + + {import.meta.env.VITE_LATEST_APP_VERSION} Marzneshin +
) } diff --git a/dashboard/vite.config.ts b/dashboard/vite.config.ts index 5814d73..9b882d7 100644 --- a/dashboard/vite.config.ts +++ b/dashboard/vite.config.ts @@ -3,25 +3,43 @@ import react from '@vitejs/plugin-react-swc' import { TanStackRouterVite } from '@tanstack/router-vite-plugin'; import tsconfigPaths from 'vite-tsconfig-paths'; import path from 'path'; +import { execSync } from 'child_process'; -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [ - TanStackRouterVite(), - tsconfigPaths(), - react() - ], - root: '.', - build: { - assetsDir: 'static', - outDir: 'dist' - }, - resolve: { - alias: [ - { - find: '@marzneshin', - replacement: path.resolve(__dirname, './src/'), - }, +export default defineConfig(({ mode }) => { + const dev = mode === "development"; + + let latestVersion = process.env.VITE_LATEST_APP_VERSION; + + if (!latestVersion) { + try { + latestVersion = dev ? + execSync("/usr/bin/git describe --tags").toString().trimEnd() : + execSync("/usr/bin/git describe --tags --abbrev=0").toString().trimEnd(); + } catch (e) { + console.error("Git versioning failed:", e); + latestVersion = "unknown"; + } + process.env.VITE_LATEST_APP_VERSION = latestVersion; + } + + return { + plugins: [ + TanStackRouterVite(), + tsconfigPaths(), + react() ], - }, + root: '.', + build: { + assetsDir: 'static', + outDir: 'dist' + }, + resolve: { + alias: [ + { + find: '@marzneshin', + replacement: path.resolve(__dirname, './src/'), + }, + ], + }, + } })