Skip to content

Commit 6f16ab5

Browse files
authored
Fix 609 app version not displayed (#613)
* Fix new version fetching, dom structure and styling of the debug dialog * Also pass git sha to prod container
1 parent 0c58984 commit 6f16ab5

5 files changed

Lines changed: 61 additions & 48 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
docker build \
6161
--progress=plain \
6262
--build-arg APP_VERSION="$APP_VERSION" \
63+
--build-arg GIT_SHA="$GIT_SHA" \
6364
-t "ossapps/splitpro-$BUILD_PLATFORM:$CHANNEL" \
6465
-t "ossapps/splitpro-$BUILD_PLATFORM:$GIT_SHA" \
6566
-t "ossapps/splitpro-$BUILD_PLATFORM:$APP_VERSION" \

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ RUN pnpm build
2323
FROM node:${NODE_VERSION}-alpine${ALPINE_VERSION} AS release
2424

2525
ARG APP_VERSION
26+
ARG GIT_SHA
2627

2728
ENV NODE_ENV=production
2829
ENV DOCKER_OUTPUT=1
@@ -41,6 +42,7 @@ COPY --from=base /app/prisma/migrations ./prisma/migrations
4142
# set this so it throws error where starting server
4243
ENV SKIP_ENV_VALIDATION="false"
4344
ENV APP_VERSION=${APP_VERSION}
45+
ENV GIT_SHA=${GIT_SHA}
4446

4547
COPY ./start.sh ./start.sh
4648

src/components/Account/DebugInfo.tsx

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import {
1313
} from '../ui/alert-dialog';
1414
import { toast } from 'sonner';
1515
import { env } from '~/env';
16+
import { cn } from '~/lib/utils';
1617

17-
export const DebugInfo: React.FC<React.PropsWithChildren<{ gitRevision: string | null }>> = ({
18-
children,
19-
gitRevision,
20-
}) => {
18+
export const DebugInfo: React.FC<React.PropsWithChildren> = ({ children }) => {
2119
const { t } = useTranslation('common');
2220
const [newVersion, setNewVersion] = React.useState<string | null>(null);
2321

@@ -37,16 +35,16 @@ export const DebugInfo: React.FC<React.PropsWithChildren<{ gitRevision: string |
3735
}
3836
};
3937

40-
if (process.env.NEXT_PUBLIC_VERSION) {
38+
if (env.NEXT_PUBLIC_VERSION) {
4139
void fetchLatestVersion();
4240
}
4341
}, []);
4442

4543
const copyToClipboard = useCallback(() => {
4644
// Copy to clipboard
4745
const debugInfo = [`UserAgent: ${navigator.userAgent}`];
48-
if (gitRevision) {
49-
debugInfo.push(`${t('account.debug_info_details.git')}: ${gitRevision}`);
46+
if (env.NEXT_PUBLIC_GIT_SHA) {
47+
debugInfo.push(`${t('account.debug_info_details.git')}: ${env.NEXT_PUBLIC_GIT_SHA}`);
5048
}
5149
if (env.NEXT_PUBLIC_VERSION) {
5250
debugInfo.push(`${t('account.debug_info_details.version')} ${env.NEXT_PUBLIC_VERSION}`);
@@ -57,33 +55,32 @@ export const DebugInfo: React.FC<React.PropsWithChildren<{ gitRevision: string |
5755
toast.error(t('account.debug_info_details.copy_failed'));
5856
console.error('Failed to copy debug info:', error);
5957
}
60-
}, [gitRevision, t]);
58+
}, [t]);
6159

6260
return (
6361
<AlertDialog>
64-
<AlertDialogTrigger>{children}</AlertDialogTrigger>
62+
<AlertDialogTrigger asChild>{children}</AlertDialogTrigger>
6563
<AlertDialogContent>
6664
<AlertDialogHeader>
6765
<AlertDialogTitle>{t('account.debug_info_details.title')}</AlertDialogTitle>
6866
<AlertDialogDescription>
69-
<p>{t('account.debug_info_details.description')}</p>
70-
<pre className="mt-4 text-wrap">
71-
{t('account.debug_info_details.user_agent')}:
72-
<br />
73-
{navigator.userAgent}
74-
</pre>
75-
{gitRevision && (
76-
<pre className="text-wrap">
77-
{t('account.debug_info_details.git')}:<br />
78-
{gitRevision}
79-
</pre>
80-
)}
81-
{env.NEXT_PUBLIC_VERSION && (
82-
<pre className="text-wrap">
83-
{t('account.debug_info_details.version')}:<br />
84-
{env.NEXT_PUBLIC_VERSION}
85-
</pre>
86-
)}
67+
{t('account.debug_info_details.description')}
68+
<DebugInfoRow
69+
label={t('account.debug_info_details.user_agent')}
70+
value={navigator.userAgent}
71+
className="mt-4"
72+
/>
73+
74+
<DebugInfoRow
75+
label={t('account.debug_info_details.git')}
76+
value={env.NEXT_PUBLIC_GIT_SHA}
77+
className="mt-4"
78+
/>
79+
<DebugInfoRow
80+
label={t('account.debug_info_details.version')}
81+
value={env.NEXT_PUBLIC_VERSION}
82+
className="mt-4"
83+
/>
8784
{newVersion && env.NEXT_PUBLIC_VERSION && newVersion !== env.NEXT_PUBLIC_VERSION ? (
8885
<p className="mt-4 text-sm text-yellow-600">
8986
{t('account.debug_info_details.new_version_available')}: {newVersion}
@@ -99,3 +96,23 @@ export const DebugInfo: React.FC<React.PropsWithChildren<{ gitRevision: string |
9996
</AlertDialog>
10097
);
10198
};
99+
100+
const Label: React.FC<React.PropsWithChildren<{ className?: string }>> = ({
101+
children,
102+
className,
103+
}) => <span className={cn('text-sm text-white', className)}>{children}</span>;
104+
105+
const Value: React.FC<React.PropsWithChildren<{ className?: string }>> = ({
106+
children,
107+
className,
108+
}) => <span className={cn('text-primary text-sm', className)}>{children}</span>;
109+
110+
export const DebugInfoRow: React.FC<
111+
React.PropsWithChildren<{ label: string; value?: string | null; className?: string }>
112+
> = ({ label, value, className }) =>
113+
value ? (
114+
<span className={cn('flex flex-col', className)}>
115+
<Label>{label}</Label>
116+
<Value>{value}</Value>
117+
</span>
118+
) : null;

src/env.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createEnv } from '@t3-oss/env-nextjs';
2+
import { execSync } from 'node:child_process';
23
import { z } from 'zod';
34

45
export const env = createEnv({
@@ -84,6 +85,7 @@ export const env = createEnv({
8485
NEXT_PUBLIC_IS_CLOUD_DEPLOYMENT: z.boolean().default(false),
8586
NEXT_PUBLIC_UPLOAD_MAX_FILE_SIZE_MB: z.coerce.number().int().positive().default(10),
8687
NEXT_PUBLIC_VERSION: z.string().optional(),
88+
NEXT_PUBLIC_GIT_SHA: z.string().optional(),
8789
},
8890

8991
/**
@@ -151,6 +153,8 @@ export const env = createEnv({
151153
? Number(process.env.UPLOAD_MAX_FILE_SIZE_MB)
152154
: 10,
153155
NEXT_PUBLIC_VERSION: process.env.APP_VERSION,
156+
NEXT_PUBLIC_GIT_SHA:
157+
process.env.GIT_SHA ?? execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim(),
154158
},
155159
/**
156160
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially

src/pages/account.tsx

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { SiGithub, SiX } from '@icons-pack/react-simple-icons';
22
import {
33
BadgeInfo,
4-
BugOff,
54
CreditCard,
65
Download,
76
DownloadCloud,
@@ -37,14 +36,12 @@ import {
3736
import { api } from '~/utils/api';
3837
import type { NextPageWithUser } from '~/types';
3938
import { DebugInfo } from '~/components/Account/DebugInfo';
40-
import { execSync } from 'node:child_process';
4139

4240
const AccountPage: NextPageWithUser<{
4341
feedBackPossible: boolean;
4442
bankConnectionEnabled: boolean;
4543
bankConnection: string;
46-
gitRevision: string | null;
47-
}> = ({ feedBackPossible, bankConnectionEnabled, bankConnection, gitRevision }) => {
44+
}> = ({ feedBackPossible, bankConnectionEnabled, bankConnection }) => {
4845
const { t } = useTranslation();
4946
const router = useRouter();
5047
const userQuery = api.user.me.useQuery();
@@ -177,7 +174,7 @@ const AccountPage: NextPageWithUser<{
177174
{t('account.import_from_splitwise')}
178175
</AccountButton>
179176

180-
<DebugInfo gitRevision={gitRevision}>
177+
<DebugInfo>
181178
<AccountButton>
182179
<BadgeInfo className="size-5 text-red-700" />
183180
{t('account.debug_info')}
@@ -201,21 +198,13 @@ const AccountPage: NextPageWithUser<{
201198

202199
AccountPage.auth = true;
203200

204-
export const getServerSideProps: GetServerSideProps = async (context) => {
205-
let gitRevision = null;
206-
try {
207-
gitRevision = execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim();
208-
} catch {}
209-
210-
return {
211-
props: {
212-
feedbackPossible: Boolean(env.FEEDBACK_EMAIL),
213-
bankConnectionEnabled: Boolean(isBankConnectionConfigured()),
214-
bankConnection: whichBankConnectionConfigured(),
215-
gitRevision,
216-
...(await customServerSideTranslations(context.locale, ['common'])),
217-
},
218-
};
219-
};
201+
export const getServerSideProps: GetServerSideProps = async (context) => ({
202+
props: {
203+
feedbackPossible: Boolean(env.FEEDBACK_EMAIL),
204+
bankConnectionEnabled: Boolean(isBankConnectionConfigured()),
205+
bankConnection: whichBankConnectionConfigured(),
206+
...(await customServerSideTranslations(context.locale, ['common'])),
207+
},
208+
});
220209

221210
export default AccountPage;

0 commit comments

Comments
 (0)