Skip to content

A local-first personal finance app

[AI] Show commit hash on edge/nightly builds (#8976)

vatsanbalaji-ossagentc679c5825377
diff --git a/packages/desktop-client/src/browser-preload.js b/packages/desktop-client/src/browser-preload.js
index ce45a5910e..667c46c61a 100644
--- a/packages/desktop-client/src/browser-preload.js
+++ b/packages/desktop-client/src/browser-preload.js
@@ -6,6 +6,7 @@ import { registerSW } from 'virtual:pwa-register';
import packageJson from '../package.json';
import SharedBrowserServerWorker from './shared-browser-server.ts?sharedworker';
+import { computeClientVersion } from './util/versions';
const backendWorkerUrl = new URL('./browser-server.js', import.meta.url);
@@ -15,11 +16,12 @@ const backendWorkerUrl = new URL('./browser-server.js', import.meta.url);
// everything else.
const IS_DEV = import.meta.env.DEV;
-const ACTUAL_VERSION = Platform.isPlaywright
- ? '99.9.9'
- : import.meta.env.REACT_APP_REVIEW_ID
- ? '.preview'
- : packageJson.version;
+const ACTUAL_VERSION = computeClientVersion({
+ isPlaywright: Platform.isPlaywright,
+ reviewId: import.meta.env.REACT_APP_REVIEW_ID,
+ commitRef: import.meta.env.REACT_APP_COMMIT_REF,
+ packageVersion: packageJson.version,
+});
// The OIDC callback (/openid-cb) is reached via a full-page navigation back
// from the OpenID provider. Routing it through the SharedWorker coordinator is
diff --git a/packages/desktop-client/src/util/versions.test.ts b/packages/desktop-client/src/util/versions.test.ts
index e94deb2c76..fd2a228aa7 100644
--- a/packages/desktop-client/src/util/versions.test.ts
+++ b/packages/desktop-client/src/util/versions.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';
-import { cmpSemanticVersion } from './versions';
+import { cmpSemanticVersion, computeClientVersion } from './versions';
describe('cmpSemanticVersion', () => {
it('compares major, minor and patch numerically', () => {
@@ -14,3 +14,60 @@ describe('cmpSemanticVersion', () => {
expect(cmpSemanticVersion('v26.8.1', '26.8.1')).toBe(0);
});
});
+
+describe('computeClientVersion', () => {
+ const base = {
+ isPlaywright: false,
+ reviewId: undefined,
+ commitRef: undefined,
+ packageVersion: '26.9.0',
+ };
+
+ it('returns a fixed version under Playwright, regardless of other inputs', () => {
+ expect(
+ computeClientVersion({
+ ...base,
+ isPlaywright: true,
+ commitRef: 'e18c8adddee6dc699ff8a8a8c65aa93e97b3a81d',
+ }),
+ ).toBe('99.9.9');
+ });
+
+ it('returns the preview marker for PR review deploys', () => {
+ expect(computeClientVersion({ ...base, reviewId: 'review-123' })).toBe(
+ '.preview',
+ );
+ });
+
+ it('prefers the preview marker when both a review ID and commit ref are set', () => {
+ expect(
+ computeClientVersion({
+ ...base,
+ reviewId: 'review-123',
+ commitRef: 'e18c8adddee6dc699ff8a8a8c65aa93e97b3a81d',
+ }),
+ ).toBe('.preview');
+ });
+
+ it('appends a short commit ref as semver build metadata when present', () => {
+ expect(
+ computeClientVersion({
+ ...base,
+ commitRef: 'e18c8adddee6dc699ff8a8a8c65aa93e97b3a81d',
+ }),
+ ).toBe('26.9.0+e18c8ad');
+ });
+
+ it('falls back to the plain package version otherwise', () => {
+ expect(computeClientVersion(base)).toBe('26.9.0');
+ });
+
+ it('does not break cmpSemanticVersion comparisons once a commit ref is appended', () => {
+ const withCommit = computeClientVersion({
+ ...base,
+ commitRef: 'e18c8adddee6dc699ff8a8a8c65aa93e97b3a81d',
+ });
+ expect(cmpSemanticVersion(withCommit, '26.9.0')).toBe(0);
+ expect(cmpSemanticVersion(withCommit, '26.10.0')).toBeLessThan(0);
+ });
+});
diff --git a/packages/desktop-client/src/util/versions.ts b/packages/desktop-client/src/util/versions.ts
index 6a9d3efd02..b3c75126a0 100644
--- a/packages/desktop-client/src/util/versions.ts
+++ b/packages/desktop-client/src/util/versions.ts
@@ -18,6 +18,38 @@ export function cmpSemanticVersion(
return x[0] - y[0] || x[1] - y[1] || x[2] - y[2];
}
+/**
+ * Computes the client version string shown in the app.
+ *
+ * Edge/nightly builds all carry the same package.json version between
+ * releases, so there's no way to tell which commit is actually running.
+ * When a commit ref is available (forwarded from Netlify's `COMMIT_REF` or
+ * GitHub Actions' `GITHUB_SHA`), append its short form as semver build
+ * metadata, e.g. `26.9.0+e18c8ad`.
+ */
+export function computeClientVersion({
+ isPlaywright,
+ reviewId,
+ commitRef,
+ packageVersion,
+}: {
+ isPlaywright: boolean;
+ reviewId: string | undefined;
+ commitRef: string | undefined;
+ packageVersion: string;
+}): string {
+ if (isPlaywright) {
+ return '99.9.9';
+ }
+ if (reviewId) {
+ return '.preview';
+ }
+ if (commitRef) {
+ return `${packageVersion}+${commitRef.slice(0, 7)}`;
+ }
+ return packageVersion;
+}
+
export async function getLatestVersion(): Promise<string | 'unknown'> {
if (Platform.isPlaywright || import.meta.env.REACT_APP_REVIEW_ID) {
return Promise.resolve('v99.9.9');
diff --git a/packages/desktop-client/vite.config.mts b/packages/desktop-client/vite.config.mts
index b27a364839..de0f6dd396 100644
--- a/packages/desktop-client/vite.config.mts
+++ b/packages/desktop-client/vite.config.mts
@@ -254,6 +254,16 @@ export default defineConfig(async ({ mode, command }) => {
process.env.REACT_APP_BRANCH = process.env.BRANCH;
}
+ // Netlify sets COMMIT_REF; GitHub Actions sets GITHUB_SHA (e.g. the
+ // Docker/npm nightly builds). Forward whichever is present so edge/nightly
+ // builds can show which commit they were built from. Release builds run in
+ // GitHub Actions on a version tag and keep their plain version.
+ const isTagBuild = process.env.GITHUB_REF_TYPE === 'tag';
+ const commitRef = process.env.COMMIT_REF || process.env.GITHUB_SHA;
+ if (commitRef && !isTagBuild) {
+ process.env.REACT_APP_COMMIT_REF = commitRef;
+ }
+
// Electron packaging (--mode=desktop) bundles loot-core directly, so skip
// all browser-only staging there.
if (mode !== 'desktop') {
diff --git a/upcoming-release-notes/show-commit-hash-on-edge-builds.md b/upcoming-release-notes/show-commit-hash-on-edge-builds.md
new file mode 100644
index 0000000000..ef74ff323a
--- /dev/null
+++ b/upcoming-release-notes/show-commit-hash-on-edge-builds.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [vatsanbalaji-ossagent]
+---
+
+Show the commit hash alongside the version number for edge/nightly builds, so it's possible to tell which commit is actually running