Skip to content

Commit 6f1bcb7

Browse files
committed
fix: embed git commit hash at build time for version display
- Add BUILD_GIT_COMMIT define in tsup.config.ts - Use build-time commit instead of runtime git command - Falls back to runtime git for development
1 parent e914c57 commit 6f1bcb7

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "autohand-cli",
3-
"version": "0.6.4",
3+
"version": "0.6.5",
44
"licenses": "SEE LICENSE IN LICENSE",
55
"description": "Autohand interactive coding agent CLI powered by LLMs.",
66
"type": "module",

src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ import type { AuthUser, LoadedConfig } from './types.js';
1313

1414
/**
1515
* Get git commit hash (short)
16+
* Uses build-time embedded commit, falls back to runtime git command for dev
1617
*/
1718
function getGitCommit(): string {
19+
// Use build-time embedded commit if available
20+
if (process.env.BUILD_GIT_COMMIT && process.env.BUILD_GIT_COMMIT !== 'undefined') {
21+
return process.env.BUILD_GIT_COMMIT;
22+
}
23+
// Fallback for development (running from source)
1824
try {
1925
return execSync('git rev-parse --short HEAD', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] }).trim();
2026
} catch {

tsup.config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
import { defineConfig } from 'tsup';
2+
import { execSync } from 'node:child_process';
3+
4+
// Get git commit at build time
5+
function getGitCommit(): string {
6+
try {
7+
return execSync('git rev-parse --short HEAD', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] }).trim();
8+
} catch {
9+
return 'unknown';
10+
}
11+
}
212

313
export default defineConfig({
414
entry: ['src/index.ts'],
@@ -15,4 +25,8 @@ export default defineConfig({
1525
noExternal: [
1626
'ink-spinner',
1727
],
28+
// Embed git commit at build time
29+
define: {
30+
'process.env.BUILD_GIT_COMMIT': JSON.stringify(getGitCommit()),
31+
},
1832
});

0 commit comments

Comments
 (0)