History

Show desktop commit hash in About panel

- embed `t3codeCommitHash` into staged desktop package metadata during builds - resolve commit hash from env/package/git and display it as About panel version

Julius Marminge committed 8 months ago

Commit c7918d51 parent df4294a2 files · +79 −1Browse files

Showing the changes to scripts (1 of 2 files). Show all

Unified · Split

scripts/build-desktop-artifact.ts+20−0
@@ -1,5 +1,7 @@
11 #!/usr/bin/env node
22
3+import { spawnSync } from "node:child_process";
4+
35 import rootPackageJson from "../package.json" with { type: "json" };
46 import desktopPackageJson from "../apps/desktop/package.json" with { type: "json" };
57 import serverPackageJson from "../apps/server/package.json" with { type: "json" };
@@ -84,6 +86,21 @@ class BuildScriptError extends Data.TaggedError("BuildScriptError")<{ · 78 unmodified lines
8486 readonly cause?: unknown;
8587 }> {}
8688
89+function resolveGitCommitHash(repoRoot: string): string {
90+ const result = spawnSync("git", ["rev-parse", "--short=12", "HEAD"], {
91+ cwd: repoRoot,
92+ encoding: "utf8",
93+ });
94+ if (result.status !== 0) {
95+ return "unknown";
96+ }
97+ const hash = result.stdout.trim();
98+ if (!/^[0-9a-f]{7,40}$/i.test(hash)) {
99+ return "unknown";
100+ }
101+ return hash.toLowerCase();
102+}
103+
87104 interface ResolvedBuildOptions {
88105 readonly platform: typeof BuildPlatform.Type;
89106 readonly target: string;
@@ -100,6 +117,7 @@ interface StagePackageJson { · 10 unmodified lines
100117 readonly name: string;
101118 readonly version: string;
102119 readonly buildVersion: string;
120+ readonly t3codeCommitHash: string;
103121 readonly private: true;
104122 readonly description: string;
105123 readonly author: string;
@@ -436,6 +454,7 @@ const buildDesktopArtifact = Effect.fn(function* (options: ResolvedBuildOptions) · 330 unmodified lines
436454 });
437455
438456 const appVersion = options.version ?? serverPackageJson.version;
457+ const commitHash = resolveGitCommitHash(repoRoot);
439458 const mkdir = options.keepStage ? fs.makeTempDirectory : fs.makeTempDirectoryScoped;
440459 const stageRoot = yield* mkdir({
441460 prefix: `t3code-desktop-${options.platform}-stage-`,
@@ -490,6 +509,7 @@ const buildDesktopArtifact = Effect.fn(function* (options: ResolvedBuildOptions) · 48 unmodified lines
490509 name: "t3-code-desktop",
491510 version: appVersion,
492511 buildVersion: appVersion,
512+ t3codeCommitHash: commitHash,
493513 private: true,
494514 description: "T3 Code desktop build",
495515 author: "T3 Tools",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t