Skip to content

Build your personal knowledge base with Trilium Notes

feat(flatpak): fold the build-info stamp into update-build-info

Elian Doran589daa3f5d1f
diff --git a/docs/Developer Guide/Developer Guide/Building/Build information.md b/docs/Developer Guide/Developer Guide/Building/Build information.md
index b1fd0437ba..4d900aaec0 100644
--- a/docs/Developer Guide/Developer Guide/Building/Build information.md
+++ b/docs/Developer Guide/Developer Guide/Building/Build information.md
@@ -1,4 +1,5 @@
# Build information
* Provides context about when the build was made and the corresponding Git revision.
* The information is displayed to the client when going in the about dialog.
-* The build information is hard-coded in `apps/server/src/services/build.ts`. This file is generated automatically via `chore:update-build-info` which itself is run automatically whenever making a build in the CI.
\ No newline at end of file
+* The build information is hard-coded in `packages/trilium-core/src/services/build.ts`. This file is generated automatically via `chore:update-build-info` which itself is run automatically whenever making a build in the CI.
+* Passing `--from-commit` stamps the commit's date instead of the current time, so that two builds of the same source agree. The Flathub build uses it, since it rebuilds published tags.
\ No newline at end of file
diff --git a/package.json b/package.json
index d82483f1e6..5df7878eae 100644
--- a/package.json
+++ b/package.json
@@ -33,7 +33,7 @@
"electron:start-prod": "pnpm desktop:start-prod",
"chore:ci-update-nightly-version": "tsx ./scripts/update-nightly-version.ts",
"chore:release-notes-body": "node --experimental-strip-types ./scripts/release-notes-body.mts",
- "chore:update-build-info": "tsx ./scripts/update-build-info.ts",
+ "chore:update-build-info": "tsx ./scripts/update-build-info.mts",
"chore:update-flake-electron": "tsx ./scripts/update-flake-electron.ts",
"chore:update-version": "tsx ./scripts/update-version.ts",
"chore:wipe-node-modules": "node --experimental-strip-types ./scripts/wipe-node-modules.mts",
diff --git a/scripts/update-build-info.mts b/scripts/update-build-info.mts
new file mode 100644
index 0000000000..cdfec994f0
--- /dev/null
+++ b/scripts/update-build-info.mts
@@ -0,0 +1,53 @@
+/**
+ * Stamps the build date and commit hash into the module behind the About dialog.
+ * CI runs it before every packaged build, through `chore:update-build-info`.
+ *
+ * Pass `--from-commit` to take the date from the commit instead of the clock, so
+ * that two builds of the same source stamp the same date. The Flathub build, which
+ * builds a published tag inside a sandbox, uses it.
+ */
+
+import { execFileSync } from "node:child_process";
+import { writeFileSync } from "node:fs";
+
+const OUTPUT_PATH = "packages/trilium-core/src/services/build.ts";
+const COMMIT_DATE_FLAG = "--from-commit";
+
+export function main(argv: string[]) {
+ const date = usesCommitDate(argv)
+ ? new Date(Number(git("log", "-1", "--format=%ct")) * 1000)
+ : new Date();
+ const buildDate = formatBuildDate(date);
+ const buildRevision = git("log", "-1", "--format=%H");
+
+ writeFileSync(OUTPUT_PATH, renderBuildInfo(buildDate, buildRevision));
+ console.log(`Stamped ${buildDate} @ ${buildRevision}`);
+}
+
+export function usesCommitDate(argv: string[]): boolean {
+ return argv.includes(COMMIT_DATE_FLAG);
+}
+
+/** Whole seconds, since the About dialog shows no finer resolution. */
+export function formatBuildDate(date: Date): string {
+ const wholeSeconds = new Date(date);
+ wholeSeconds.setMilliseconds(0);
+ return wholeSeconds.toISOString().replace(".000", "");
+}
+
+export function renderBuildInfo(buildDate: string, buildRevision: string): string {
+ return `export default {
+ buildDate: "${buildDate}",
+ buildRevision: "${buildRevision}"
+};
+`;
+}
+
+function git(...args: string[]): string {
+ return execFileSync("git", args).toString().trim();
+}
+
+// Only when run as a script — the helpers above are imported by the spec.
+if (process.argv[1] === import.meta.filename) {
+ main(process.argv.slice(2));
+}
diff --git a/scripts/update-build-info.spec.ts b/scripts/update-build-info.spec.ts
new file mode 100644
index 0000000000..d652dd835a
--- /dev/null
+++ b/scripts/update-build-info.spec.ts
@@ -0,0 +1,32 @@
+import { describe, expect, it } from "vitest";
+
+import { formatBuildDate, renderBuildInfo, usesCommitDate } from "./update-build-info.mjs";
+
+describe("formatBuildDate", () => {
+ it("formats to whole seconds, whether or not the date carries milliseconds", () => {
+ expect(formatBuildDate(new Date("2026-09-21T17:49:03.481Z"))).toBe("2026-09-21T17:49:03Z");
+ expect(formatBuildDate(new Date("2026-09-21T17:49:03.000Z"))).toBe("2026-09-21T17:49:03Z");
+ // A commit epoch reaches the formatter as whole seconds.
+ expect(formatBuildDate(new Date(1758476943 * 1000))).toBe("2025-09-21T17:49:03Z");
+ });
+});
+
+describe("renderBuildInfo", () => {
+ it("renders the module the About dialog reads", () => {
+ expect(renderBuildInfo("2026-09-21T17:49:03Z", "a0908a6e1e1741a3c3824d803da07300183dcb0c"))
+ .toBe(`export default {
+ buildDate: "2026-09-21T17:49:03Z",
+ buildRevision: "a0908a6e1e1741a3c3824d803da07300183dcb0c"
+};
+`);
+ });
+});
+
+describe("usesCommitDate", () => {
+ it("stamps the clock unless --from-commit is passed", () => {
+ // Every CI caller of chore:update-build-info relies on this default.
+ expect(usesCommitDate([])).toBe(false);
+ expect(usesCommitDate([ "--frozen-lockfile" ])).toBe(false);
+ expect(usesCommitDate([ "--from-commit" ])).toBe(true);
+ });
+});
diff --git a/scripts/update-build-info.ts b/scripts/update-build-info.ts
deleted file mode 100644
index 9420c0fc98..0000000000
--- a/scripts/update-build-info.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import child_process from "child_process";
-import fs from "fs";
-
-function getBuildDate() {
- const now = new Date();
- now.setMilliseconds(0);
- return now.toISOString().replace(".000", "");
-}
-
-function getGitRevision() {
- return child_process.execSync('git log -1 --format="%H"').toString("utf-8").trimEnd();
-}
-
-const output = `\
-export default {
- buildDate: "${getBuildDate()}",
- buildRevision: "${getGitRevision()}"
-};
-`;
-
-fs.writeFileSync("packages/trilium-core/src/services/build.ts", output);