refactor: updated vite config to inject add version metadata into the app on build (#841)
Browse files* refactor: removes commit.json and used vite.config to load these variables
* updated precommit hook
* updated the pre start script
* updated the workflows
- .github/workflows/commit.yaml +0 -39
- .github/workflows/update-stable.yml +1 -2
- .husky/pre-commit +0 -11
- app/commit.json +0 -1
- app/components/settings/debug/DebugTab.tsx +7 -3
- app/components/settings/providers/ProvidersTab.tsx +9 -12
- app/lib/hooks/useSettings.tsx +9 -7
- app/vite-env.d.ts +2 -0
- pre-start.cjs +19 -4
- vite.config.ts +16 -0
.github/workflows/commit.yaml
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
name: Update Commit Hash File
|
| 2 |
-
|
| 3 |
-
on:
|
| 4 |
-
push:
|
| 5 |
-
branches:
|
| 6 |
-
- main
|
| 7 |
-
|
| 8 |
-
permissions:
|
| 9 |
-
contents: write
|
| 10 |
-
|
| 11 |
-
jobs:
|
| 12 |
-
update-commit:
|
| 13 |
-
if: contains(github.event.head_commit.message, '#release') != true
|
| 14 |
-
runs-on: ubuntu-latest
|
| 15 |
-
|
| 16 |
-
steps:
|
| 17 |
-
- name: Checkout the code
|
| 18 |
-
uses: actions/checkout@v3
|
| 19 |
-
|
| 20 |
-
- name: Setup Node.js
|
| 21 |
-
uses: actions/setup-node@v4
|
| 22 |
-
with:
|
| 23 |
-
node-version: '20'
|
| 24 |
-
- name: Get the latest commit hash
|
| 25 |
-
run: |
|
| 26 |
-
echo "COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
|
| 27 |
-
echo "CURRENT_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
|
| 28 |
-
|
| 29 |
-
- name: Update commit file
|
| 30 |
-
run: |
|
| 31 |
-
echo "{ \"commit\": \"$COMMIT_HASH\", \"version\": \"$CURRENT_VERSION\" }" > app/commit.json
|
| 32 |
-
|
| 33 |
-
- name: Commit and push the update
|
| 34 |
-
run: |
|
| 35 |
-
git config --global user.name "github-actions[bot]"
|
| 36 |
-
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
| 37 |
-
git add app/commit.json
|
| 38 |
-
git commit -m "chore: update commit hash to $COMMIT_HASH"
|
| 39 |
-
git push
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.github/workflows/update-stable.yml
CHANGED
|
@@ -166,8 +166,7 @@ jobs:
|
|
| 166 |
- name: Commit and Tag Release
|
| 167 |
run: |
|
| 168 |
git pull
|
| 169 |
-
|
| 170 |
-
git add package.json pnpm-lock.yaml changelog.md app/commit.json
|
| 171 |
git commit -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
|
| 172 |
git tag "v${{ steps.bump_version.outputs.new_version }}"
|
| 173 |
git push
|
|
|
|
| 166 |
- name: Commit and Tag Release
|
| 167 |
run: |
|
| 168 |
git pull
|
| 169 |
+
git add package.json pnpm-lock.yaml changelog.md
|
|
|
|
| 170 |
git commit -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
|
| 171 |
git tag "v${{ steps.bump_version.outputs.new_version }}"
|
| 172 |
git push
|
.husky/pre-commit
CHANGED
|
@@ -29,15 +29,4 @@ if ! pnpm lint; then
|
|
| 29 |
exit 1
|
| 30 |
fi
|
| 31 |
|
| 32 |
-
# Update commit.json with the latest commit hash
|
| 33 |
-
echo "Updating commit.json with the latest commit hash..."
|
| 34 |
-
COMMIT_HASH=$(git rev-parse HEAD)
|
| 35 |
-
if [ $? -ne 0 ]; then
|
| 36 |
-
echo "β Failed to get commit hash. Ensure you are in a git repository."
|
| 37 |
-
exit 1
|
| 38 |
-
fi
|
| 39 |
-
|
| 40 |
-
echo "{ \"commit\": \"$COMMIT_HASH\" }" > app/commit.json
|
| 41 |
-
git add app/commit.json
|
| 42 |
-
|
| 43 |
echo "π All checks passed! Committing changes..."
|
|
|
|
| 29 |
exit 1
|
| 30 |
fi
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
echo "π All checks passed! Committing changes..."
|
app/commit.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{ "commit": "ab5cde30a126f6540f0afb4d6d6e6be6a764ddca", "version": "0.0.3" }
|
|
|
|
|
|
app/components/settings/debug/DebugTab.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import React, { useCallback, useEffect, useState } from 'react';
|
| 2 |
import { useSettings } from '~/lib/hooks/useSettings';
|
| 3 |
-
import commit from '~/commit.json';
|
| 4 |
import { toast } from 'react-toastify';
|
| 5 |
import { providerBaseUrlEnvKeys } from '~/utils/constants';
|
| 6 |
|
|
@@ -44,11 +43,16 @@ interface CommitData {
|
|
| 44 |
version?: string;
|
| 45 |
}
|
| 46 |
|
| 47 |
-
const connitJson: CommitData =
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
const LOCAL_PROVIDERS = ['Ollama', 'LMStudio', 'OpenAILike'];
|
|
|
|
| 50 |
const versionHash = connitJson.commit;
|
| 51 |
const versionTag = connitJson.version;
|
|
|
|
| 52 |
const GITHUB_URLS = {
|
| 53 |
original: 'https://api.github.com/repos/stackblitz-labs/bolt.diy/commits/main',
|
| 54 |
fork: 'https://api.github.com/repos/Stijnus/bolt.new-any-llm/commits/main',
|
|
@@ -524,7 +528,7 @@ export default function DebugTab() {
|
|
| 524 |
<div className="mt-3 pt-3 border-t border-bolt-elements-surface-hover">
|
| 525 |
<p className="text-xs text-bolt-elements-textSecondary">Version</p>
|
| 526 |
<p className="text-sm font-medium text-bolt-elements-textPrimary font-mono">
|
| 527 |
-
{
|
| 528 |
<span className="ml-2 text-xs text-bolt-elements-textSecondary">
|
| 529 |
(v{versionTag || '0.0.1'}) - {isLatestBranch ? 'nightly' : 'stable'}
|
| 530 |
</span>
|
|
|
|
| 1 |
import React, { useCallback, useEffect, useState } from 'react';
|
| 2 |
import { useSettings } from '~/lib/hooks/useSettings';
|
|
|
|
| 3 |
import { toast } from 'react-toastify';
|
| 4 |
import { providerBaseUrlEnvKeys } from '~/utils/constants';
|
| 5 |
|
|
|
|
| 43 |
version?: string;
|
| 44 |
}
|
| 45 |
|
| 46 |
+
const connitJson: CommitData = {
|
| 47 |
+
commit: __COMMIT_HASH,
|
| 48 |
+
version: __APP_VERSION,
|
| 49 |
+
};
|
| 50 |
|
| 51 |
const LOCAL_PROVIDERS = ['Ollama', 'LMStudio', 'OpenAILike'];
|
| 52 |
+
|
| 53 |
const versionHash = connitJson.commit;
|
| 54 |
const versionTag = connitJson.version;
|
| 55 |
+
|
| 56 |
const GITHUB_URLS = {
|
| 57 |
original: 'https://api.github.com/repos/stackblitz-labs/bolt.diy/commits/main',
|
| 58 |
fork: 'https://api.github.com/repos/Stijnus/bolt.new-any-llm/commits/main',
|
|
|
|
| 528 |
<div className="mt-3 pt-3 border-t border-bolt-elements-surface-hover">
|
| 529 |
<p className="text-xs text-bolt-elements-textSecondary">Version</p>
|
| 530 |
<p className="text-sm font-medium text-bolt-elements-textPrimary font-mono">
|
| 531 |
+
{connitJson.commit.slice(0, 7)}
|
| 532 |
<span className="ml-2 text-xs text-bolt-elements-textSecondary">
|
| 533 |
(v{versionTag || '0.0.1'}) - {isLatestBranch ? 'nightly' : 'stable'}
|
| 534 |
</span>
|
app/components/settings/providers/ProvidersTab.tsx
CHANGED
|
@@ -35,8 +35,8 @@ export default function ProvidersTab() {
|
|
| 35 |
newFilteredProviders.sort((a, b) => a.name.localeCompare(b.name));
|
| 36 |
|
| 37 |
// Split providers into regular and URL-configurable
|
| 38 |
-
const regular = newFilteredProviders.filter(p => !URL_CONFIGURABLE_PROVIDERS.includes(p.name));
|
| 39 |
-
const urlConfigurable = newFilteredProviders.filter(p => URL_CONFIGURABLE_PROVIDERS.includes(p.name));
|
| 40 |
|
| 41 |
setFilteredProviders([...regular, ...urlConfigurable]);
|
| 42 |
}, [providers, searchTerm, isLocalModel]);
|
|
@@ -112,8 +112,8 @@ export default function ProvidersTab() {
|
|
| 112 |
);
|
| 113 |
};
|
| 114 |
|
| 115 |
-
const regularProviders = filteredProviders.filter(p => !URL_CONFIGURABLE_PROVIDERS.includes(p.name));
|
| 116 |
-
const urlConfigurableProviders = filteredProviders.filter(p => URL_CONFIGURABLE_PROVIDERS.includes(p.name));
|
| 117 |
|
| 118 |
return (
|
| 119 |
<div className="p-4">
|
|
@@ -128,22 +128,19 @@ export default function ProvidersTab() {
|
|
| 128 |
</div>
|
| 129 |
|
| 130 |
{/* Regular Providers Grid */}
|
| 131 |
-
<div className="grid grid-cols-2 gap-4 mb-8">
|
| 132 |
-
{regularProviders.map(renderProviderCard)}
|
| 133 |
-
</div>
|
| 134 |
|
| 135 |
{/* URL Configurable Providers Section */}
|
| 136 |
{urlConfigurableProviders.length > 0 && (
|
| 137 |
<div className="mt-8">
|
| 138 |
<h3 className="text-lg font-semibold mb-2 text-bolt-elements-textPrimary">Experimental Providers</h3>
|
| 139 |
<p className="text-sm text-bolt-elements-textSecondary mb-4">
|
| 140 |
-
These providers are experimental and allow you to run AI models locally or connect to your own
|
|
|
|
| 141 |
</p>
|
| 142 |
-
<div className="space-y-4">
|
| 143 |
-
{urlConfigurableProviders.map(renderProviderCard)}
|
| 144 |
-
</div>
|
| 145 |
</div>
|
| 146 |
)}
|
| 147 |
</div>
|
| 148 |
);
|
| 149 |
-
}
|
|
|
|
| 35 |
newFilteredProviders.sort((a, b) => a.name.localeCompare(b.name));
|
| 36 |
|
| 37 |
// Split providers into regular and URL-configurable
|
| 38 |
+
const regular = newFilteredProviders.filter((p) => !URL_CONFIGURABLE_PROVIDERS.includes(p.name));
|
| 39 |
+
const urlConfigurable = newFilteredProviders.filter((p) => URL_CONFIGURABLE_PROVIDERS.includes(p.name));
|
| 40 |
|
| 41 |
setFilteredProviders([...regular, ...urlConfigurable]);
|
| 42 |
}, [providers, searchTerm, isLocalModel]);
|
|
|
|
| 112 |
);
|
| 113 |
};
|
| 114 |
|
| 115 |
+
const regularProviders = filteredProviders.filter((p) => !URL_CONFIGURABLE_PROVIDERS.includes(p.name));
|
| 116 |
+
const urlConfigurableProviders = filteredProviders.filter((p) => URL_CONFIGURABLE_PROVIDERS.includes(p.name));
|
| 117 |
|
| 118 |
return (
|
| 119 |
<div className="p-4">
|
|
|
|
| 128 |
</div>
|
| 129 |
|
| 130 |
{/* Regular Providers Grid */}
|
| 131 |
+
<div className="grid grid-cols-2 gap-4 mb-8">{regularProviders.map(renderProviderCard)}</div>
|
|
|
|
|
|
|
| 132 |
|
| 133 |
{/* URL Configurable Providers Section */}
|
| 134 |
{urlConfigurableProviders.length > 0 && (
|
| 135 |
<div className="mt-8">
|
| 136 |
<h3 className="text-lg font-semibold mb-2 text-bolt-elements-textPrimary">Experimental Providers</h3>
|
| 137 |
<p className="text-sm text-bolt-elements-textSecondary mb-4">
|
| 138 |
+
These providers are experimental and allow you to run AI models locally or connect to your own
|
| 139 |
+
infrastructure. They require additional setup but offer more flexibility.
|
| 140 |
</p>
|
| 141 |
+
<div className="space-y-4">{urlConfigurableProviders.map(renderProviderCard)}</div>
|
|
|
|
|
|
|
| 142 |
</div>
|
| 143 |
)}
|
| 144 |
</div>
|
| 145 |
);
|
| 146 |
+
}
|
app/lib/hooks/useSettings.tsx
CHANGED
|
@@ -12,14 +12,16 @@ import { useCallback, useEffect, useState } from 'react';
|
|
| 12 |
import Cookies from 'js-cookie';
|
| 13 |
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
| 14 |
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
|
| 15 |
-
import commit from '~/commit.json';
|
| 16 |
|
| 17 |
interface CommitData {
|
| 18 |
commit: string;
|
| 19 |
version?: string;
|
| 20 |
}
|
| 21 |
|
| 22 |
-
const
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
export function useSettings() {
|
| 25 |
const providers = useStore(providersStore);
|
|
@@ -34,7 +36,7 @@ export function useSettings() {
|
|
| 34 |
const checkIsStableVersion = async () => {
|
| 35 |
try {
|
| 36 |
const stableResponse = await fetch(
|
| 37 |
-
`https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/refs/tags/v${
|
| 38 |
);
|
| 39 |
|
| 40 |
if (!stableResponse.ok) {
|
|
@@ -44,7 +46,7 @@ export function useSettings() {
|
|
| 44 |
|
| 45 |
const stableData = (await stableResponse.json()) as CommitData;
|
| 46 |
|
| 47 |
-
return
|
| 48 |
} catch (error) {
|
| 49 |
console.warn('Error checking stable version:', error);
|
| 50 |
return false;
|
|
@@ -105,16 +107,16 @@ export function useSettings() {
|
|
| 105 |
let checkCommit = Cookies.get('commitHash');
|
| 106 |
|
| 107 |
if (checkCommit === undefined) {
|
| 108 |
-
checkCommit =
|
| 109 |
}
|
| 110 |
|
| 111 |
-
if (savedLatestBranch === undefined || checkCommit !==
|
| 112 |
// If setting hasn't been set by user, check version
|
| 113 |
checkIsStableVersion().then((isStable) => {
|
| 114 |
const shouldUseLatest = !isStable;
|
| 115 |
latestBranchStore.set(shouldUseLatest);
|
| 116 |
Cookies.set('isLatestBranch', String(shouldUseLatest));
|
| 117 |
-
Cookies.set('commitHash', String(
|
| 118 |
});
|
| 119 |
} else {
|
| 120 |
latestBranchStore.set(savedLatestBranch === 'true');
|
|
|
|
| 12 |
import Cookies from 'js-cookie';
|
| 13 |
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
| 14 |
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
|
|
|
|
| 15 |
|
| 16 |
interface CommitData {
|
| 17 |
commit: string;
|
| 18 |
version?: string;
|
| 19 |
}
|
| 20 |
|
| 21 |
+
const versionData: CommitData = {
|
| 22 |
+
commit: __COMMIT_HASH,
|
| 23 |
+
version: __APP_VERSION,
|
| 24 |
+
};
|
| 25 |
|
| 26 |
export function useSettings() {
|
| 27 |
const providers = useStore(providersStore);
|
|
|
|
| 36 |
const checkIsStableVersion = async () => {
|
| 37 |
try {
|
| 38 |
const stableResponse = await fetch(
|
| 39 |
+
`https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/refs/tags/v${versionData.version}/app/commit.json`,
|
| 40 |
);
|
| 41 |
|
| 42 |
if (!stableResponse.ok) {
|
|
|
|
| 46 |
|
| 47 |
const stableData = (await stableResponse.json()) as CommitData;
|
| 48 |
|
| 49 |
+
return versionData.commit === stableData.commit;
|
| 50 |
} catch (error) {
|
| 51 |
console.warn('Error checking stable version:', error);
|
| 52 |
return false;
|
|
|
|
| 107 |
let checkCommit = Cookies.get('commitHash');
|
| 108 |
|
| 109 |
if (checkCommit === undefined) {
|
| 110 |
+
checkCommit = versionData.commit;
|
| 111 |
}
|
| 112 |
|
| 113 |
+
if (savedLatestBranch === undefined || checkCommit !== versionData.commit) {
|
| 114 |
// If setting hasn't been set by user, check version
|
| 115 |
checkIsStableVersion().then((isStable) => {
|
| 116 |
const shouldUseLatest = !isStable;
|
| 117 |
latestBranchStore.set(shouldUseLatest);
|
| 118 |
Cookies.set('isLatestBranch', String(shouldUseLatest));
|
| 119 |
+
Cookies.set('commitHash', String(versionData.commit));
|
| 120 |
});
|
| 121 |
} else {
|
| 122 |
latestBranchStore.set(savedLatestBranch === 'true');
|
app/vite-env.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
declare const __COMMIT_HASH: string;
|
| 2 |
+
declare const __APP_VERSION: string;
|
pre-start.cjs
CHANGED
|
@@ -1,4 +1,18 @@
|
|
| 1 |
-
const {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
console.log(`
|
| 4 |
β
ββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -6,6 +20,7 @@ console.log(`
|
|
| 6 |
β‘οΈ Welcome β‘οΈ
|
| 7 |
β
ββββββββββββββββββββββββββββββββββββββββ
|
| 8 |
`);
|
| 9 |
-
console.log('π Current
|
| 10 |
-
console.log('
|
| 11 |
-
console.log('
|
|
|
|
|
|
| 1 |
+
const { execSync } =require('child_process');
|
| 2 |
+
|
| 3 |
+
// Get git hash with fallback
|
| 4 |
+
const getGitHash = () => {
|
| 5 |
+
try {
|
| 6 |
+
return execSync('git rev-parse --short HEAD').toString().trim();
|
| 7 |
+
} catch {
|
| 8 |
+
return 'no-git-info';
|
| 9 |
+
}
|
| 10 |
+
};
|
| 11 |
+
|
| 12 |
+
let commitJson = {
|
| 13 |
+
hash: JSON.stringify(getGitHash()),
|
| 14 |
+
version: JSON.stringify(process.env.npm_package_version),
|
| 15 |
+
};
|
| 16 |
|
| 17 |
console.log(`
|
| 18 |
β
ββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 20 |
β‘οΈ Welcome β‘οΈ
|
| 21 |
β
ββββββββββββββββββββββββββββββββββββββββ
|
| 22 |
`);
|
| 23 |
+
console.log('π Current Version Tag:', `v${commitJson.version}`);
|
| 24 |
+
console.log('π Current Commit Version:', commitJson.hash);
|
| 25 |
+
console.log(' Please wait until the URL appears here');
|
| 26 |
+
console.log('β
ββββββββββββββββββββββββββββββββββββββββ
');
|
vite.config.ts
CHANGED
|
@@ -5,8 +5,24 @@ import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
|
| 5 |
import { optimizeCssModules } from 'vite-plugin-optimize-css-modules';
|
| 6 |
import tsconfigPaths from 'vite-tsconfig-paths';
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
export default defineConfig((config) => {
|
| 9 |
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
build: {
|
| 11 |
target: 'esnext',
|
| 12 |
},
|
|
|
|
| 5 |
import { optimizeCssModules } from 'vite-plugin-optimize-css-modules';
|
| 6 |
import tsconfigPaths from 'vite-tsconfig-paths';
|
| 7 |
|
| 8 |
+
import { execSync } from 'child_process';
|
| 9 |
+
|
| 10 |
+
// Get git hash with fallback
|
| 11 |
+
const getGitHash = () => {
|
| 12 |
+
try {
|
| 13 |
+
return execSync('git rev-parse --short HEAD').toString().trim();
|
| 14 |
+
} catch {
|
| 15 |
+
return 'no-git-info';
|
| 16 |
+
}
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
|
| 20 |
export default defineConfig((config) => {
|
| 21 |
return {
|
| 22 |
+
define: {
|
| 23 |
+
__COMMIT_HASH__: JSON.stringify(getGitHash()),
|
| 24 |
+
__APP_VERSION__: JSON.stringify(process.env.npm_package_version),
|
| 25 |
+
},
|
| 26 |
build: {
|
| 27 |
target: 'esnext',
|
| 28 |
},
|