From dfb865e433db1d73b90ebc826b89fb230d7586ce Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Wed, 4 Mar 2026 19:07:30 -0800 Subject: [PATCH 1/2] Add git SHA to CLI version string --- src/cli/setup.ts | 3 ++- src/cli/version.ts | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/cli/version.ts diff --git a/src/cli/setup.ts b/src/cli/setup.ts index e843a10..7e9be8e 100644 --- a/src/cli/setup.ts +++ b/src/cli/setup.ts @@ -3,6 +3,7 @@ import { program } from 'commander' import color from 'kleur' import pkg from '../../package.json' +import { SHA } from './version' import { cronList, cronLog, @@ -29,7 +30,7 @@ import { program .name('toes') - .version(`v${pkg.version}`, '-v, --version') + .version(`v${pkg.version}-${SHA}`, '-v, --version') .addHelpText('beforeAll', (ctx) => { if (ctx.command === program) { return color.bold().cyan('🐾 Toes') + color.gray(' - personal web appliance\n') diff --git a/src/cli/version.ts b/src/cli/version.ts new file mode 100644 index 0000000..b2a17ae --- /dev/null +++ b/src/cli/version.ts @@ -0,0 +1,3 @@ +const result = Bun.spawnSync(['git', 'rev-parse', '--short', 'HEAD']) + +export const SHA = result.stdout.toString().trim() From 0ae4e6e9b2940c4814e47ba83e3c05d212ee8fd9 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Wed, 4 Mar 2026 19:09:46 -0800 Subject: [PATCH 2/2] Embed git SHA at build time via define flag --- scripts/build.ts | 3 +++ src/cli/version.ts | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/build.ts b/scripts/build.ts index a9ec5a9..c9483da 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -9,6 +9,7 @@ import { join } from 'path' const DIST_DIR = join(import.meta.dir, '..', 'dist') const ENTRY_POINT = join(import.meta.dir, '..', 'src', 'cli', 'index.ts') +const GIT_SHA = Bun.spawnSync(['git', 'rev-parse', '--short', 'HEAD']).stdout.toString().trim() || 'unknown' interface BuildTarget { arch: string @@ -40,6 +41,7 @@ async function buildCurrent() { 'bun', '--minify', '--sourcemap=external', + `--define=__GIT_SHA__="${GIT_SHA}"`, '--outfile', output, ], { @@ -73,6 +75,7 @@ async function buildTarget(target: BuildTarget) { `bun-${target.os}-${target.arch}`, '--minify', '--sourcemap=external', + `--define=__GIT_SHA__="${GIT_SHA}"`, '--outfile', output, ], { diff --git a/src/cli/version.ts b/src/cli/version.ts index b2a17ae..0f3dac6 100644 --- a/src/cli/version.ts +++ b/src/cli/version.ts @@ -1,3 +1,3 @@ -const result = Bun.spawnSync(['git', 'rev-parse', '--short', 'HEAD']) +declare var __GIT_SHA__: string -export const SHA = result.stdout.toString().trim() +export const SHA: string = typeof __GIT_SHA__ !== 'undefined' ? __GIT_SHA__ : 'dev'