From 132f2e4b2b8a8e21897c251d02fe6ea2775e42c6 Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Mon, 13 Nov 2023 21:17:17 -0800 Subject: [PATCH] chore(trading): add git hash and tag into settings view (#5207) --- apps/trading/components/settings/settings.tsx | 27 ++++++++++++++++--- apps/trading/next.config.js | 19 +++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/apps/trading/components/settings/settings.tsx b/apps/trading/components/settings/settings.tsx index 0d5f5eb43..978480ee4 100644 --- a/apps/trading/components/settings/settings.tsx +++ b/apps/trading/components/settings/settings.tsx @@ -3,6 +3,7 @@ import { Switch, ToastPositionSetter } from '@vegaprotocol/ui-toolkit'; import { useThemeSwitcher } from '@vegaprotocol/react-helpers'; import { useTelemetryApproval } from '../../lib/hooks/use-telemetry-approval'; import type { ReactNode } from 'react'; +import classNames from 'classnames'; export const Settings = () => { const { theme, setTheme } = useThemeSwitcher(); @@ -31,6 +32,18 @@ export const Settings = () => { + +
+ {process.env.GIT_TAG && ( + <> +
{t('Version')}
+
{process.env.GIT_TAG}
+ + )} +
{t('Git commit hash')}
+
{process.env.GIT_COMMIT}
+
+
); }; @@ -39,16 +52,22 @@ const SettingsGroup = ({ label, helpText, children, + inline = true, }: { label: string; - helpText?: string; children: ReactNode; + helpText?: string; + inline?: boolean; }) => { return ( -
-
+
+
- {helpText &&

{helpText}

} + {helpText &&

{helpText}

}
{children}
diff --git a/apps/trading/next.config.js b/apps/trading/next.config.js index 4c6a4b4a4..dd4796f56 100644 --- a/apps/trading/next.config.js +++ b/apps/trading/next.config.js @@ -1,3 +1,4 @@ +const childProcess = require('child_process'); // eslint-disable-next-line @typescript-eslint/no-var-requires const withNx = require('@nx/next/plugins/with-nx'); const { withSentryConfig } = require('@sentry/nextjs'); @@ -10,6 +11,20 @@ const sentryWebpackOptions = { token: SENTRY_AUTH_TOKEN, }; +const commitHash = childProcess + .execSync('git rev-parse HEAD') + .toString() + .trim(); + +// Get the tag of the last commit +const commitLog = childProcess + .execSync('git log --decorate --oneline -1') + .toString() + .trim(); + +const tagMatch = commitLog.match(/tag: ([^,)]+)/); +const tag = tagMatch ? tagMatch[1] : ''; + /** * @type {import('@nx/next/plugins/with-nx').WithNxOptions} **/ @@ -20,6 +35,10 @@ const nextConfig = { svgr: false, }, pageExtensions: ['page.tsx', 'page.jsx'], + env: { + GIT_COMMIT: commitHash, + GIT_TAG: tag, + }, }; module.exports = SENTRY_AUTH_TOKEN