From b8d12629ce75afe2c9e44ad999b317fb50d4f972 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 7 Dec 2025 23:56:57 +0000 Subject: [PATCH 1/2] Initial plan From 6ba37dd1e1cb9d76d8727cc6144c5a91e76a27b3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Dec 2025 00:03:17 +0000 Subject: [PATCH 2/2] Fix footer showing undefined git SHA by injecting it at build time Co-authored-by: coder13 <881394+coder13@users.noreply.github.com> --- package.json | 4 ++-- src/App/Footer.tsx | 14 ++++++++++---- vite.config.ts | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index d6b9193..6f9214e 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "private": true, "type": "module", "scripts": { - "dev": "VITE_GIT_SHA=`git rev-parse --short HEAD` GENERATE_SOURCEMAP=false vite", - "build": "VITE_GIT_SHA=`git rev-parse --short HEAD` tsc && vite build", + "dev": "GENERATE_SOURCEMAP=false vite", + "build": "tsc && vite build", "lint": "eslint ./", "type-check": "tsc --noEmit", "test": "vitest run", diff --git a/src/App/Footer.tsx b/src/App/Footer.tsx index 6cd45c7..fbb92d7 100644 --- a/src/App/Footer.tsx +++ b/src/App/Footer.tsx @@ -15,13 +15,19 @@ const linkStyle = { }, }; +const gitSha = import.meta.env.VITE_GIT_SHA; + const links = [ { text: 'GitHub', url: 'https://github.com/coder13/delegateDashboard' }, { text: 'Contact', url: 'mailto:choover11@gmail.com' }, - { - text: `${import.meta.env.VITE_GIT_SHA}`, - url: `https://github.com/coder13/delegateDashboard/commit/${import.meta.env.VITE_GIT_SHA}`, - }, + ...(gitSha + ? [ + { + text: gitSha, + url: `https://github.com/coder13/delegateDashboard/commit/${gitSha}`, + }, + ] + : []), ]; const Footer = () => { diff --git a/vite.config.ts b/vite.config.ts index 8eb3c49..4e6d812 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,10 +1,25 @@ import react from '@vitejs/plugin-react'; +import { execSync } from 'child_process'; import { defineConfig } from 'vite'; import { VitePWA } from 'vite-plugin-pwa'; import svgrPlugin from 'vite-plugin-svgr'; import viteTsconfigPaths from 'vite-tsconfig-paths'; +// Get git SHA, fallback to environment variable or undefined +const getGitSha = () => { + try { + // Try to get from git command + return execSync('git rev-parse --short HEAD').toString().trim(); + } catch { + // Fallback to environment variable (useful for Netlify) + return process.env.VITE_GIT_SHA || process.env.COMMIT_REF?.substring(0, 7); + } +}; + // https://vitejs.dev/config/ export default defineConfig({ plugins: [react(), viteTsconfigPaths(), svgrPlugin(), VitePWA()], + define: { + 'import.meta.env.VITE_GIT_SHA': JSON.stringify(getGitSha()), + }, });