From 51f0e01258b92c77952d4534bb8ce8c618b2700c Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 5 Oct 2026 09:24:43 +0400 Subject: [PATCH] refac --- .github/workflows/docker.yaml | 1 + .github/workflows/release-pypi.yml | 3 ++ Dockerfile | 5 ++- hatch_build.py | 1 - scripts/build-info.js | 43 ++++++++++++++++++ src/app.d.ts | 4 ++ .../components/admin/Settings/General.svelte | 12 ++--- src/lib/components/chat/Settings/About.svelte | 16 +++---- src/lib/components/common/BuildVersion.svelte | 17 +++++++ src/lib/constants.ts | 1 + src/lib/i18n/locales/ar-BH/translation.json | 14 ++++-- src/lib/i18n/locales/ar/translation.json | 14 ++++-- src/lib/i18n/locales/az-AZ/translation.json | 14 ++++-- src/lib/i18n/locales/bg-BG/translation.json | 14 ++++-- src/lib/i18n/locales/bn-BD/translation.json | 14 ++++-- src/lib/i18n/locales/bo-TB/translation.json | 14 ++++-- src/lib/i18n/locales/bs-BA/translation.json | 14 ++++-- src/lib/i18n/locales/ca-ES/translation.json | 14 ++++-- src/lib/i18n/locales/ceb-PH/translation.json | 14 ++++-- src/lib/i18n/locales/cs-CZ/translation.json | 14 ++++-- src/lib/i18n/locales/da-DK/translation.json | 14 ++++-- src/lib/i18n/locales/de-DE/translation.json | 14 ++++-- src/lib/i18n/locales/dg-DG/translation.json | 14 ++++-- src/lib/i18n/locales/el-GR/translation.json | 14 ++++-- src/lib/i18n/locales/en-GB/translation.json | 14 ++++-- src/lib/i18n/locales/en-US/translation.json | 9 ++-- src/lib/i18n/locales/es-ES/translation.json | 14 ++++-- src/lib/i18n/locales/et-EE/translation.json | 14 ++++-- src/lib/i18n/locales/eu-ES/translation.json | 14 ++++-- src/lib/i18n/locales/fa-IR/translation.json | 44 +++++++++++-------- src/lib/i18n/locales/fi-FI/translation.json | 14 ++++-- src/lib/i18n/locales/fil-PH/translation.json | 14 ++++-- src/lib/i18n/locales/fo-FO/translation.json | 14 ++++-- src/lib/i18n/locales/fr-CA/translation.json | 14 ++++-- src/lib/i18n/locales/fr-FR/translation.json | 14 ++++-- src/lib/i18n/locales/gl-ES/translation.json | 14 ++++-- src/lib/i18n/locales/he-IL/translation.json | 14 ++++-- src/lib/i18n/locales/hi-IN/translation.json | 14 ++++-- src/lib/i18n/locales/hr-HR/translation.json | 14 ++++-- src/lib/i18n/locales/hu-HU/translation.json | 14 ++++-- src/lib/i18n/locales/id-ID/translation.json | 14 ++++-- src/lib/i18n/locales/ie-GA/translation.json | 14 ++++-- src/lib/i18n/locales/it-IT/translation.json | 14 ++++-- src/lib/i18n/locales/ja-JP/translation.json | 4 +- src/lib/i18n/locales/ka-GE/translation.json | 14 ++++-- src/lib/i18n/locales/kab-DZ/translation.json | 14 ++++-- src/lib/i18n/locales/ko-KR/translation.json | 14 ++++-- src/lib/i18n/locales/lt-LT/translation.json | 14 ++++-- src/lib/i18n/locales/lv-LV/translation.json | 14 ++++-- src/lib/i18n/locales/ms-MY/translation.json | 9 ++-- src/lib/i18n/locales/nb-NO/translation.json | 14 ++++-- src/lib/i18n/locales/nl-NL/translation.json | 14 ++++-- src/lib/i18n/locales/pa-IN/translation.json | 14 ++++-- src/lib/i18n/locales/pl-PL/translation.json | 14 ++++-- src/lib/i18n/locales/pt-BR/translation.json | 14 ++++-- src/lib/i18n/locales/pt-PT/translation.json | 14 ++++-- src/lib/i18n/locales/ro-RO/translation.json | 14 ++++-- src/lib/i18n/locales/ru-RU/translation.json | 14 ++++-- src/lib/i18n/locales/sk-SK/translation.json | 14 ++++-- src/lib/i18n/locales/sl-SI/translation.json | 14 ++++-- src/lib/i18n/locales/sr-RS/translation.json | 14 ++++-- src/lib/i18n/locales/sv-SE/translation.json | 14 ++++-- src/lib/i18n/locales/ta-IN/translation.json | 14 ++++-- src/lib/i18n/locales/th-TH/translation.json | 14 ++++-- src/lib/i18n/locales/tk-TM/translation.json | 14 ++++-- src/lib/i18n/locales/tr-TR/translation.json | 12 ++++- src/lib/i18n/locales/ug-CN/translation.json | 14 ++++-- src/lib/i18n/locales/uk-UA/translation.json | 14 ++++-- src/lib/i18n/locales/ur-PK/translation.json | 14 ++++-- .../i18n/locales/uz-Cyrl-UZ/translation.json | 14 ++++-- .../i18n/locales/uz-Latn-UZ/translation.json | 14 ++++-- src/lib/i18n/locales/vi-VN/translation.json | 14 ++++-- src/lib/i18n/locales/zh-CN/translation.json | 14 ++++-- src/lib/i18n/locales/zh-TW/translation.json | 14 ++++-- src/routes/(app)/+layout.svelte | 10 +++-- static/pyodide/pyodide-lock.json | 6 +-- svelte.config.js | 23 ++++------ vite.config.ts | 5 ++- 78 files changed, 808 insertions(+), 243 deletions(-) create mode 100644 scripts/build-info.js create mode 100644 src/lib/components/common/BuildVersion.svelte diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index ab9283fa02..1802e8f336 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -136,6 +136,7 @@ jobs: sbom: true build-args: | BUILD_HASH=${{ github.sha }} + BUILD_CHANNEL=${{ github.ref == 'refs/heads/dev' && 'dev' || (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && 'main' || 'unknown' }} ${{ matrix.variant.build_args }} - name: Export digest diff --git a/.github/workflows/release-pypi.yml b/.github/workflows/release-pypi.yml index 9995ccedae..40cebc5028 100644 --- a/.github/workflows/release-pypi.yml +++ b/.github/workflows/release-pypi.yml @@ -28,6 +28,9 @@ jobs: with: python-version: 3.11 - name: Build + env: + APP_BUILD_CHANNEL: main + APP_BUILD_HASH: ${{ github.sha }} run: | python -m pip install --upgrade pip pip install build diff --git a/Dockerfile b/Dockerfile index 08d7a71eec..4bf9cfc57c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,7 @@ ARG USE_AUXILIARY_EMBEDDING_MODEL=TaylorAI/bge-micro-v2 ARG USE_TIKTOKEN_ENCODING_NAME="cl100k_base" ARG BUILD_HASH=dev-build +ARG BUILD_CHANNEL=unknown # Override at your own risk - non-root configurations are untested ARG UID=0 ARG GID=0 @@ -26,6 +27,7 @@ ARG GID=0 ######## WebUI frontend ######## FROM --platform=$BUILDPLATFORM node:22-alpine3.20 AS build ARG BUILD_HASH +ARG BUILD_CHANNEL ARG USE_SLIM ARG UID ARG GID @@ -43,6 +45,7 @@ RUN npm ci --force COPY . . ENV APP_BUILD_HASH=${BUILD_HASH} +ENV APP_BUILD_CHANNEL=${BUILD_CHANNEL} RUN npm run build && \ if [ "$USE_SLIM" = "true" ]; then find build -type f -name '*.map' -delete; fi @@ -225,7 +228,7 @@ RUN if [ "$USE_PERMISSION_HARDENING" = "true" ]; then \ USER $UID:$GID ARG BUILD_HASH -ENV WEBUI_BUILD_VERSION=${BUILD_HASH} +ENV WEBUI_BUILD_HASH=${BUILD_HASH} ENV DOCKER=true CMD [ "bash", "start.sh"] diff --git a/hatch_build.py b/hatch_build.py index bf47545680..623b368b78 100644 --- a/hatch_build.py +++ b/hatch_build.py @@ -17,7 +17,6 @@ class CustomBuildHook(BuildHookInterface): stderr.write('### npm install\n') subprocess.run([npm, 'install', '--force'], check=True) # noqa: S603 stderr.write('\n### npm run build\n') - os.environ['APP_BUILD_HASH'] = version node_options = os.environ.get('NODE_OPTIONS', '') if '--max-old-space-size' not in node_options: os.environ['NODE_OPTIONS'] = f'{node_options} --max-old-space-size=8192'.strip() diff --git a/scripts/build-info.js b/scripts/build-info.js new file mode 100644 index 0000000000..c8b8816d9e --- /dev/null +++ b/scripts/build-info.js @@ -0,0 +1,43 @@ +import { execFileSync } from 'node:child_process'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +export function resolveBuildInfo({ + env = process.env, + cwd = fileURLToPath(new URL('../', import.meta.url)) +} = {}) { + const git = (...args) => { + try { + return execFileSync('git', args, { + cwd, + encoding: 'utf8', + stdio: ['ignore', 'pipe', 'ignore'] + }).trim(); + } catch { + return ''; + } + }; + + const suppliedHash = env.APP_BUILD_HASH ?? ''; + const hash = /^(?:[a-f\d]{7,40}|[a-f\d]{64})$/i.test(suppliedHash) + ? suppliedHash + : git('rev-parse', 'HEAD'); + let channel = env.APP_BUILD_CHANNEL; + if (!['main', 'dev', 'unknown'].includes(channel)) { + const branch = git('branch', '--show-current'); + channel = branch === 'main' || branch === 'dev' ? branch : 'unknown'; + if (!branch && hash) { + try { + const { version } = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8')); + if (git('tag', '--points-at', 'HEAD').split('\n').includes(`v${version}`)) { + channel = 'main'; + } + } catch { + // Source archives may have neither Git metadata nor a package version. + } + } + } + + return { channel, hash }; +} diff --git a/src/app.d.ts b/src/app.d.ts index f59b884c51..e3b97f2232 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,6 +1,10 @@ // See https://kit.svelte.dev/docs/types#app // for information about these interfaces declare global { + const APP_VERSION: string; + const APP_BUILD_HASH: string; + const APP_BUILD_CHANNEL: 'main' | 'dev' | 'unknown'; + namespace App { // interface Error {} // interface Locals {} diff --git a/src/lib/components/admin/Settings/General.svelte b/src/lib/components/admin/Settings/General.svelte index 88b4412db7..65f91be375 100644 --- a/src/lib/components/admin/Settings/General.svelte +++ b/src/lib/components/admin/Settings/General.svelte @@ -9,8 +9,8 @@ import SettingsSelect from '$lib/components/common/SettingsSelect.svelte'; import LanguageModeSelect from '$lib/components/common/LanguageModeSelect.svelte'; import Switch from '$lib/components/common/Switch.svelte'; - import Tooltip from '$lib/components/common/Tooltip.svelte'; - import { WEBUI_BUILD_HASH, WEBUI_VERSION } from '$lib/constants'; + import BuildVersion from '$lib/components/common/BuildVersion.svelte'; + import { WEBUI_BUILD_CHANNEL, WEBUI_VERSION } from '$lib/constants'; import { banners as _banners, config, showChangelog } from '$lib/stores'; import type { Banner } from '$lib/types'; import { compareVersion } from '$lib/utils'; @@ -112,7 +112,7 @@ banners = [...$_banners]; - if ($config?.features?.enable_version_update_check) { + if (WEBUI_BUILD_CHANNEL === 'main' && $config?.features?.enable_version_update_check) { checkForVersionUpdates(); } }); @@ -137,9 +137,9 @@ {$i18n.t('settings.admin.general.version.label')}
- v{WEBUI_VERSION} + - {#if $config?.features?.enable_version_update_check} + {#if WEBUI_BUILD_CHANNEL === 'main' && $config?.features?.enable_version_update_check} {#if version.latest === null} {$i18n.t('Could not check for updates')}
- {#if $config?.features?.enable_version_update_check} + {#if WEBUI_BUILD_CHANNEL === 'main' && $config?.features?.enable_version_update_check} - {#if $config?.features?.enable_version_update_check} + {#if WEBUI_BUILD_CHANNEL === 'main' && $config?.features?.enable_version_update_check}