Skip to content

Commit

Permalink
CI: set git ref and timestamp in env (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
incognitojam authored Jun 20, 2024
1 parent bd8b8db commit 5295e8c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ jobs:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-pnpm

- name: get build info
id: build_info
run: echo timestamp=$(git show -s --format=%cI) >> $GITHUB_OUTPUT

- run: pnpm install
- run: pnpm build:production
env:
VITE_APP_GIT_SHA: ${{ github.sha }}
VITE_APP_GIT_TIMESTAMP: ${{ steps.build_info.outputs.timestamp }}

- name: Upload built project
uses: actions/upload-artifact@v4
Expand Down
37 changes: 24 additions & 13 deletions src/components/AppHeader/AccountMenu.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState } from 'react';
import React, { useCallback, useMemo } from 'react';
import dayjs from 'dayjs';

import {
Expand All @@ -17,18 +17,29 @@ const logOut = async () => {
}
};

const AccountMenu = ({ profile, open, anchorEl, onClose, ...rest }) => {
const [buildTimestamp, setBuildTimestamp] = useState('');
const [version, setVersion] = useState('');
const Version = () => {
const sha = import.meta.env.VITE_APP_GIT_SHA;
const timestamp = import.meta.env.VITE_APP_GIT_TIMESTAMP;

let content = ['Version: '];

useEffect(() => {
setVersion(import.meta.env.VITE_APP_GIT_SHA?.substring(0, 7) || 'dev');
if (sha) {
const commitUrl = `https://github.com/commaai/connect/commit/${sha}`;
content.push(<a key="0" className="text-blue-400 underline" href={commitUrl} target="_blank" rel="noreferrer">{sha.substring(0, 7)}</a>);

const buildDate = import.meta.env.VITE_APP_GIT_TIMESTAMP;
if (buildDate) {
setBuildTimestamp(`, ${dayjs(buildDate).fromNow()}`);
if (timestamp) {
const buildDate = dayjs(timestamp).fromNow();
content.push(`, ${buildDate}`);
}
}, []);
} else {
content.push('dev');
}

return <span className="text-xs text-[#ffffff66]">{content}</span>
};

const AccountMenu = ({ profile, open, anchorEl, onClose, ...rest }) => {
const version = useMemo(() => <Version />, []);

const onLogOut = useCallback(() => {
onClose();
Expand All @@ -44,10 +55,10 @@ const AccountMenu = ({ profile, open, anchorEl, onClose, ...rest }) => {
transformOrigin={{ vertical: 'top', horizontal: 'right' }}
{...rest}
>
<ListItem className="text-white py-3 px-4 flex-col items-start">
<ListItem className="text-white pt-3 pb-4 px-4 flex-col items-start gap-2">
<span className="font-bold">{profile.email}</span>
<span className="text-xs text-[#ffffff66] pt-2">{ profile.user_id }</span>
<span className="text-xs text-[#ffffff66] pt-2">{`Version: ${version}${buildTimestamp}`}</span>
<span className="text-xs text-[#ffffff66]">{profile.user_id}</span>
{version}
</ListItem>
<Divider />
<MenuItem
Expand Down

0 comments on commit 5295e8c

Please sign in to comment.