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 @@
1#!/usr/bin/env node1#!/usr/bin/env node
2 2
3import { spawnSync } from "node:child_process";
4
3import rootPackageJson from "../package.json" with { type: "json" };5import rootPackageJson from "../package.json" with { type: "json" };
4import desktopPackageJson from "../apps/desktop/package.json" with { type: "json" };6import desktopPackageJson from "../apps/desktop/package.json" with { type: "json" };
5import serverPackageJson from "../apps/server/package.json" with { type: "json" };7import serverPackageJson from "../apps/server/package.json" with { type: "json" };
@@ -84,6 +86,21 @@ class BuildScriptError extends Data.TaggedError("BuildScriptError")<{ · 78 unmodified lines
84 readonly cause?: unknown;86 readonly cause?: unknown;
85}> {}87}> {}
86 88
89function 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
87interface ResolvedBuildOptions {104interface ResolvedBuildOptions {
88 readonly platform: typeof BuildPlatform.Type;105 readonly platform: typeof BuildPlatform.Type;
89 readonly target: string;106 readonly target: string;
@@ -100,6 +117,7 @@ interface StagePackageJson { · 10 unmodified lines
100 readonly name: string;117 readonly name: string;
101 readonly version: string;118 readonly version: string;
102 readonly buildVersion: string;119 readonly buildVersion: string;
120 readonly t3codeCommitHash: string;
103 readonly private: true;121 readonly private: true;
104 readonly description: string;122 readonly description: string;
105 readonly author: string;123 readonly author: string;
@@ -436,6 +454,7 @@ const buildDesktopArtifact = Effect.fn(function* (options: ResolvedBuildOptions) · 330 unmodified lines
436 });454 });
437 455
438 const appVersion = options.version ?? serverPackageJson.version;456 const appVersion = options.version ?? serverPackageJson.version;
457 const commitHash = resolveGitCommitHash(repoRoot);
439 const mkdir = options.keepStage ? fs.makeTempDirectory : fs.makeTempDirectoryScoped;458 const mkdir = options.keepStage ? fs.makeTempDirectory : fs.makeTempDirectoryScoped;
440 const stageRoot = yield* mkdir({459 const stageRoot = yield* mkdir({
441 prefix: `t3code-desktop-${options.platform}-stage-`,460 prefix: `t3code-desktop-${options.platform}-stage-`,
@@ -490,6 +509,7 @@ const buildDesktopArtifact = Effect.fn(function* (options: ResolvedBuildOptions) · 48 unmodified lines
490 name: "t3-code-desktop",509 name: "t3-code-desktop",
491 version: appVersion,510 version: appVersion,
492 buildVersion: appVersion,511 buildVersion: appVersion,
512 t3codeCommitHash: commitHash,
493 private: true,513 private: true,
494 description: "T3 Code desktop build",514 description: "T3 Code desktop build",
495 author: "T3 Tools",515 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