updated to use settings for branch selection

This commit is contained in:
Dustin Loring 2024-12-15 12:56:25 -05:00
parent 348f396d32
commit 69b1dc4c9a
6 changed files with 55 additions and 35 deletions

View File

@ -3,7 +3,7 @@ name: Update Commit Hash File
on: on:
push: push:
branches: branches:
- 'main' - main
permissions: permissions:
contents: write contents: write
@ -20,17 +20,14 @@ jobs:
- name: Get the latest commit hash - name: Get the latest commit hash
run: echo "COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV run: echo "COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Get the current branch name
run: echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Update commit file - name: Update commit file
run: | run: |
echo "{ \"commit\": \"$COMMIT_HASH\", \"branch\": \"$BRANCH_NAME\" }" > app/commit.json echo "{ \"commit\": \"$COMMIT_HASH\" }" > app/commit.json
- name: Commit and push the update - name: Commit and push the update
run: | run: |
git config --global user.name "github-actions[bot]" git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com" git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add app/commit.json git add app/commit.json
git commit -m "chore: update commit hash to $COMMIT_HASH on branch $BRANCH_NAME" git commit -m "chore: update commit hash to $COMMIT_HASH"
git push git push

View File

@ -1 +1 @@
{ "commit": "87a90718d31bd8ec501cb32f863efd26156fb1e2", "branch": "main" } { "commit": "87a90718d31bd8ec501cb32f863efd26156fb1e2" }

View File

@ -202,7 +202,7 @@ const checkProviderStatus = async (url: string | null, providerName: string): Pr
}; };
export default function DebugTab() { export default function DebugTab() {
const { providers } = useSettings(); const { providers, useLatestBranch } = useSettings();
const [activeProviders, setActiveProviders] = useState<ProviderStatus[]>([]); const [activeProviders, setActiveProviders] = useState<ProviderStatus[]>([]);
const [updateMessage, setUpdateMessage] = useState<string>(''); const [updateMessage, setUpdateMessage] = useState<string>('');
const [systemInfo] = useState<SystemInfo>(getSystemInfo()); const [systemInfo] = useState<SystemInfo>(getSystemInfo());
@ -261,34 +261,26 @@ export default function DebugTab() {
setIsCheckingUpdate(true); setIsCheckingUpdate(true);
setUpdateMessage('Checking for updates...'); setUpdateMessage('Checking for updates...');
// Get current branch from commit.json const branchToCheck = useLatestBranch ? 'main' : 'stable';
const currentBranch = commit.branch || 'main'; console.log(`[Debug] Checking for updates against ${branchToCheck} branch`);
// Fetch the commit data from the specified URL for the current branch const localCommitResponse = await fetch(GITHUB_URLS.commitJson(branchToCheck));
const localCommitResponse = await fetch(GITHUB_URLS.commitJson(currentBranch));
if (!localCommitResponse.ok) { if (!localCommitResponse.ok) {
throw new Error('Failed to fetch repository information'); throw new Error('Failed to fetch repository information');
} }
// Define the expected structure of the commit data const localCommitData = await localCommitResponse.json();
interface CommitData { const remoteCommitHash = localCommitData.commit;
commit: string; const currentCommitHash = versionHash;
branch: string;
}
const localCommitData: CommitData = await localCommitResponse.json(); if (remoteCommitHash !== currentCommitHash) {
const originalCommitHash = localCommitData.commit;
const currentLocalCommitHash = commit.commit;
if (originalCommitHash !== currentLocalCommitHash) {
setUpdateMessage( setUpdateMessage(
`Update available from original repository (${currentBranch} branch)!\n` + `Update available from ${branchToCheck} branch!\n` +
`Current: ${currentLocalCommitHash.slice(0, 7)}\n` + `Current: ${currentCommitHash.slice(0, 7)}\n` +
`Latest: ${originalCommitHash.slice(0, 7)}` `Latest: ${remoteCommitHash.slice(0, 7)}`
); );
} else { } else {
setUpdateMessage(`You are on the latest version from the original repository (${currentBranch} branch)`); setUpdateMessage(`You are on the latest version from the ${branchToCheck} branch`);
} }
} catch (error) { } catch (error) {
setUpdateMessage('Failed to check for updates'); setUpdateMessage('Failed to check for updates');
@ -296,7 +288,7 @@ export default function DebugTab() {
} finally { } finally {
setIsCheckingUpdate(false); setIsCheckingUpdate(false);
} }
}, [isCheckingUpdate]); }, [isCheckingUpdate, useLatestBranch]);
const handleCopyToClipboard = useCallback(() => { const handleCopyToClipboard = useCallback(() => {
const debugInfo = { const debugInfo = {
@ -311,14 +303,17 @@ export default function DebugTab() {
responseTime: provider.responseTime, responseTime: provider.responseTime,
url: provider.url, url: provider.url,
})), })),
Version: versionHash, Version: {
hash: versionHash.slice(0, 7),
branch: useLatestBranch ? 'main' : 'stable'
},
Timestamp: new Date().toISOString(), Timestamp: new Date().toISOString(),
}; };
navigator.clipboard.writeText(JSON.stringify(debugInfo, null, 2)).then(() => { navigator.clipboard.writeText(JSON.stringify(debugInfo, null, 2)).then(() => {
toast.success('Debug information copied to clipboard!'); toast.success('Debug information copied to clipboard!');
}); });
}, [activeProviders, systemInfo]); }, [activeProviders, systemInfo, useLatestBranch]);
return ( return (
<div className="p-4 space-y-6"> <div className="p-4 space-y-6">

View File

@ -3,7 +3,7 @@ import { Switch } from '~/components/ui/Switch';
import { useSettings } from '~/lib/hooks/useSettings'; import { useSettings } from '~/lib/hooks/useSettings';
export default function FeaturesTab() { export default function FeaturesTab() {
const { debug, enableDebugMode, isLocalModel, enableLocalModels, eventLogs, enableEventLogs } = useSettings(); const { debug, enableDebugMode, isLocalModel, enableLocalModels, eventLogs, enableEventLogs, useLatestBranch, enableLatestBranch } = useSettings();
const handleToggle = (enabled: boolean) => { const handleToggle = (enabled: boolean) => {
enableDebugMode(enabled); enableDebugMode(enabled);
@ -14,10 +14,19 @@ export default function FeaturesTab() {
<div className="p-4 bg-bolt-elements-bg-depth-2 border border-bolt-elements-borderColor rounded-lg mb-4"> <div className="p-4 bg-bolt-elements-bg-depth-2 border border-bolt-elements-borderColor rounded-lg mb-4">
<div className="mb-6"> <div className="mb-6">
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Optional Features</h3> <h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Optional Features</h3>
<div className="flex items-center justify-between mb-2"> <div className="space-y-4">
<div className="flex items-center justify-between">
<span className="text-bolt-elements-textPrimary">Debug Features</span> <span className="text-bolt-elements-textPrimary">Debug Features</span>
<Switch className="ml-auto" checked={debug} onCheckedChange={handleToggle} /> <Switch className="ml-auto" checked={debug} onCheckedChange={handleToggle} />
</div> </div>
<div className="flex items-center justify-between">
<div>
<span className="text-bolt-elements-textPrimary">Use Main Branch</span>
<p className="text-sm text-bolt-elements-textSecondary">Check for updates against the main branch instead of stable</p>
</div>
<Switch className="ml-auto" checked={useLatestBranch} onCheckedChange={enableLatestBranch} />
</div>
</div>
</div> </div>
<div className="mb-6 border-t border-bolt-elements-borderColor pt-4"> <div className="mb-6 border-t border-bolt-elements-borderColor pt-4">

View File

@ -5,6 +5,7 @@ import {
isLocalModelsEnabled, isLocalModelsEnabled,
LOCAL_PROVIDERS, LOCAL_PROVIDERS,
providersStore, providersStore,
useLatestBranch,
} from '~/lib/stores/settings'; } from '~/lib/stores/settings';
import { useCallback, useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
@ -16,6 +17,7 @@ export function useSettings() {
const debug = useStore(isDebugMode); const debug = useStore(isDebugMode);
const eventLogs = useStore(isEventLogsEnabled); const eventLogs = useStore(isEventLogsEnabled);
const isLocalModel = useStore(isLocalModelsEnabled); const isLocalModel = useStore(isLocalModelsEnabled);
const useLatest = useStore(useLatestBranch);
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]); const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
// reading values from cookies on mount // reading values from cookies on mount
@ -60,6 +62,13 @@ export function useSettings() {
if (savedLocalModels) { if (savedLocalModels) {
isLocalModelsEnabled.set(savedLocalModels === 'true'); isLocalModelsEnabled.set(savedLocalModels === 'true');
} }
// load latest branch setting from cookies
const savedLatestBranch = Cookies.get('useLatestBranch');
if (savedLatestBranch) {
useLatestBranch.set(savedLatestBranch === 'true');
}
}, []); }, []);
// writing values to cookies on change // writing values to cookies on change
@ -111,6 +120,12 @@ export function useSettings() {
Cookies.set('isLocalModelsEnabled', String(enabled)); Cookies.set('isLocalModelsEnabled', String(enabled));
}, []); }, []);
const enableLatestBranch = useCallback((enabled: boolean) => {
useLatestBranch.set(enabled);
logStore.logSystem(`Main branch updates ${enabled ? 'enabled' : 'disabled'}`);
Cookies.set('useLatestBranch', String(enabled));
}, []);
return { return {
providers, providers,
activeProviders, activeProviders,
@ -121,5 +136,7 @@ export function useSettings() {
enableEventLogs, enableEventLogs,
isLocalModel, isLocalModel,
enableLocalModels, enableLocalModels,
useLatestBranch: useLatest,
enableLatestBranch,
}; };
} }

View File

@ -46,3 +46,5 @@ export const isDebugMode = atom(false);
export const isEventLogsEnabled = atom(false); export const isEventLogsEnabled = atom(false);
export const isLocalModelsEnabled = atom(true); export const isLocalModelsEnabled = atom(true);
export const useLatestBranch = atom(false);