Merge pull request 'Show the build's version and commit in Settings' (#9) from build-version into main
Reviewed-on: #9
This commit is contained in:
commit
2d415d88a3
4 changed files with 52 additions and 1 deletions
|
|
@ -1,4 +1,8 @@
|
||||||
.git
|
# Keep just enough of .git for the build to read the current commit.
|
||||||
|
.git/*
|
||||||
|
!.git/HEAD
|
||||||
|
!.git/refs
|
||||||
|
!.git/packed-refs
|
||||||
.claude
|
.claude
|
||||||
node_modules
|
node_modules
|
||||||
.svelte-kit
|
.svelte-kit
|
||||||
|
|
|
||||||
3
src/app.d.ts
vendored
3
src/app.d.ts
vendored
|
|
@ -1,6 +1,9 @@
|
||||||
// See https://svelte.dev/docs/kit/types#app.d.ts
|
// See https://svelte.dev/docs/kit/types#app.d.ts
|
||||||
declare global {
|
declare global {
|
||||||
namespace App {}
|
namespace App {}
|
||||||
|
|
||||||
|
/** Stamped in by vite.config.ts at build time. */
|
||||||
|
const __BUILD__: { version: string; commit: string; dirty: boolean; time: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
export {};
|
export {};
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
type Tab = 'appearance' | 'input' | 'sync';
|
type Tab = 'appearance' | 'input' | 'sync';
|
||||||
let tab = $state<Tab>('appearance');
|
let tab = $state<Tab>('appearance');
|
||||||
const s = settings.data;
|
const s = settings.data;
|
||||||
|
const build = __BUILD__;
|
||||||
|
|
||||||
let testing = $state(false);
|
let testing = $state(false);
|
||||||
let testResult = $state<{ ok: boolean; text: string } | null>(null);
|
let testResult = $state<{ ok: boolean; text: string } | null>(null);
|
||||||
|
|
@ -55,6 +56,9 @@
|
||||||
<button class:active={tab === 'appearance'} onclick={() => (tab = 'appearance')}>Appearance</button>
|
<button class:active={tab === 'appearance'} onclick={() => (tab = 'appearance')}>Appearance</button>
|
||||||
<button class:active={tab === 'input'} onclick={() => (tab = 'input')}>Pen & touch</button>
|
<button class:active={tab === 'input'} onclick={() => (tab = 'input')}>Pen & touch</button>
|
||||||
<button class:active={tab === 'sync'} onclick={() => (tab = 'sync')}>Sync</button>
|
<button class:active={tab === 'sync'} onclick={() => (tab = 'sync')}>Sync</button>
|
||||||
|
<div class="build" title={`Commit ${build.commit}\nBuilt ${new Date(build.time).toLocaleString()}`}>
|
||||||
|
v{build.version} · {build.commit.slice(0, 7)}{build.dirty ? '-dirty' : ''}
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<section>
|
<section>
|
||||||
<button class="icon-btn close" title="Close" onclick={close}><XIcon size={18} /></button>
|
<button class="icon-btn close" title="Close" onclick={close}><XIcon size={18} /></button>
|
||||||
|
|
@ -187,6 +191,14 @@
|
||||||
color: var(--faint);
|
color: var(--faint);
|
||||||
padding: 0 10px 8px;
|
padding: 0 10px 8px;
|
||||||
}
|
}
|
||||||
|
.build {
|
||||||
|
margin-top: auto;
|
||||||
|
padding: 0 10px;
|
||||||
|
font-family: var(--mono-font);
|
||||||
|
font-size: 11px;
|
||||||
|
color: var(--faint);
|
||||||
|
user-select: text;
|
||||||
|
}
|
||||||
nav button {
|
nav button {
|
||||||
text-align: left;
|
text-align: left;
|
||||||
border: 0;
|
border: 0;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,40 @@
|
||||||
|
import { execSync } from 'node:child_process';
|
||||||
|
import { existsSync, readFileSync } from 'node:fs';
|
||||||
import { sveltekit } from '@sveltejs/kit/vite';
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
import { defineConfig } from 'vitest/config';
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
|
/** Current commit. Uses git when available, else reads .git directly (the Docker build has no git binary). */
|
||||||
|
function gitCommit(): { commit: string; dirty: boolean } {
|
||||||
|
if (process.env.GIT_COMMIT) return { commit: process.env.GIT_COMMIT, dirty: false };
|
||||||
|
try {
|
||||||
|
const commit = execSync('git rev-parse HEAD', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
|
||||||
|
const dirty = execSync('git status --porcelain --untracked-files=no', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim() !== '';
|
||||||
|
return { commit, dirty };
|
||||||
|
} catch {
|
||||||
|
/* fall through */
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const head = readFileSync('.git/HEAD', 'utf8').trim();
|
||||||
|
if (!head.startsWith('ref: ')) return { commit: head, dirty: false };
|
||||||
|
const ref = head.slice(5);
|
||||||
|
if (existsSync(`.git/${ref}`)) return { commit: readFileSync(`.git/${ref}`, 'utf8').trim(), dirty: false };
|
||||||
|
const packed = readFileSync('.git/packed-refs', 'utf8').split('\n').find((l) => l.endsWith(` ${ref}`));
|
||||||
|
if (packed) return { commit: packed.split(' ')[0], dirty: false };
|
||||||
|
} catch {
|
||||||
|
/* no repository */
|
||||||
|
}
|
||||||
|
return { commit: 'unknown', dirty: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
const build = {
|
||||||
|
version: JSON.parse(readFileSync('package.json', 'utf8')).version as string,
|
||||||
|
...gitCommit(),
|
||||||
|
time: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [sveltekit()],
|
plugins: [sveltekit()],
|
||||||
|
define: { __BUILD__: JSON.stringify(build) },
|
||||||
test: {
|
test: {
|
||||||
include: ['src/**/*.test.ts'],
|
include: ['src/**/*.test.ts'],
|
||||||
environment: 'node'
|
environment: 'node'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue