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