Display repository commit count as the Synapsis version
Hop-State: A_06FP98T1AFPC938R80XJ3J0 Hop-Proposal: R_06FP98S721MFZV1BVBVDTK8 Hop-Task: T_06FP98D0VF530A9XJ2HHHWR Hop-Attempt: AT_06FP98D0VFKNWCN4EJD46YR
This commit is contained in:
@@ -32,6 +32,7 @@ export function RightSidebar() {
|
||||
const [version, setVersion] = useState<{
|
||||
version: string;
|
||||
commit: string | null;
|
||||
commitCount: number | null;
|
||||
buildDate: string | null;
|
||||
} | null>(null);
|
||||
|
||||
@@ -80,7 +81,7 @@ export function RightSidebar() {
|
||||
fetch('/api/version')
|
||||
.then(res => res.json())
|
||||
.then(data => setVersion(data))
|
||||
.catch(() => setVersion({ version: 'unknown', commit: null, buildDate: null }));
|
||||
.catch(() => setVersion({ version: 'unknown', commit: null, commitCount: null, buildDate: null }));
|
||||
|
||||
return () => window.removeEventListener('synapsis:node-updated', handleNodeUpdated);
|
||||
}, []);
|
||||
@@ -154,8 +155,8 @@ export function RightSidebar() {
|
||||
<p style={{ color: 'var(--foreground-secondary)', fontSize: '13px' }}>
|
||||
Running{' '}
|
||||
<a href="https://synapsis.gnosyslabs.xyz" target="_blank" rel="noopener noreferrer" style={{ color: 'var(--accent)' }}>Synapsis</a>
|
||||
{version?.commit
|
||||
? ` ${version.commit.slice(0, 7)}`
|
||||
{version?.commitCount !== null && version?.commitCount !== undefined
|
||||
? ` ${version.commitCount}`
|
||||
: version?.version
|
||||
? ` ${version.version}`
|
||||
: ''}
|
||||
|
||||
@@ -63,7 +63,9 @@ export async function buildAnnouncement(): Promise<SwarmAnnouncement> {
|
||||
description,
|
||||
logoUrl,
|
||||
publicKey,
|
||||
softwareVersion: buildInfo.commit || buildInfo.version,
|
||||
softwareVersion: buildInfo.commitCount !== null
|
||||
? String(buildInfo.commitCount)
|
||||
: buildInfo.version,
|
||||
userCount,
|
||||
postCount,
|
||||
capabilities,
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { getCurrentBuildInfo } from './version';
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
describe('build information', () => {
|
||||
it('exposes the repository commit count as a number', () => {
|
||||
vi.stubEnv('APP_COMMIT_COUNT', '288');
|
||||
|
||||
expect(getCurrentBuildInfo().commitCount).toBe(288);
|
||||
});
|
||||
|
||||
it('ignores an unavailable commit count', () => {
|
||||
vi.stubEnv('APP_COMMIT_COUNT', 'unknown');
|
||||
|
||||
expect(getCurrentBuildInfo().commitCount).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -3,13 +3,19 @@ import packageJson from '../../package.json';
|
||||
export interface BuildInfo {
|
||||
version: string;
|
||||
commit: string | null;
|
||||
commitCount: number | null;
|
||||
buildDate: string | null;
|
||||
}
|
||||
|
||||
export function getCurrentBuildInfo(): BuildInfo {
|
||||
const parsedCommitCount = Number.parseInt(process.env.APP_COMMIT_COUNT || '', 10);
|
||||
|
||||
return {
|
||||
version: process.env.APP_VERSION || packageJson.version || 'dev',
|
||||
commit: process.env.APP_COMMIT || null,
|
||||
commitCount: Number.isSafeInteger(parsedCommitCount) && parsedCommitCount >= 0
|
||||
? parsedCommitCount
|
||||
: null,
|
||||
buildDate: process.env.APP_BUILD_DATE || null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user