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:
push:
branches:
- 'main'
- main
permissions:
contents: write
@ -20,17 +20,14 @@ jobs:
- name: Get the latest commit hash
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
run: |
echo "{ \"commit\": \"$COMMIT_HASH\", \"branch\": \"$BRANCH_NAME\" }" > app/commit.json
echo "{ \"commit\": \"$COMMIT_HASH\" }" > app/commit.json
- name: Commit and push the update
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add app/commit.json
git commit -m "chore: update commit hash to $COMMIT_HASH on branch $BRANCH_NAME"
git push
git commit -m "chore: update commit hash to $COMMIT_HASH"
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() {
const { providers } = useSettings();
const { providers, useLatestBranch } = useSettings();
const [activeProviders, setActiveProviders] = useState<ProviderStatus[]>([]);
const [updateMessage, setUpdateMessage] = useState<string>('');
const [systemInfo] = useState<SystemInfo>(getSystemInfo());
@ -261,34 +261,26 @@ export default function DebugTab() {
setIsCheckingUpdate(true);
setUpdateMessage('Checking for updates...');
// Get current branch from commit.json
const currentBranch = commit.branch || 'main';
const branchToCheck = useLatestBranch ? 'main' : 'stable';
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(currentBranch));
const localCommitResponse = await fetch(GITHUB_URLS.commitJson(branchToCheck));
if (!localCommitResponse.ok) {
throw new Error('Failed to fetch repository information');
}
// Define the expected structure of the commit data
interface CommitData {
commit: string;
branch: string;
}
const localCommitData = await localCommitResponse.json();
const remoteCommitHash = localCommitData.commit;
const currentCommitHash = versionHash;
const localCommitData: CommitData = await localCommitResponse.json();
const originalCommitHash = localCommitData.commit;
const currentLocalCommitHash = commit.commit;
if (originalCommitHash !== currentLocalCommitHash) {
if (remoteCommitHash !== currentCommitHash) {
setUpdateMessage(
`Update available from original repository (${currentBranch} branch)!\n` +
`Current: ${currentLocalCommitHash.slice(0, 7)}\n` +
`Latest: ${originalCommitHash.slice(0, 7)}`
`Update available from ${branchToCheck} branch!\n` +
`Current: ${currentCommitHash.slice(0, 7)}\n` +
`Latest: ${remoteCommitHash.slice(0, 7)}`
);
} 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) {
setUpdateMessage('Failed to check for updates');
@ -296,7 +288,7 @@ export default function DebugTab() {
} finally {
setIsCheckingUpdate(false);
}
}, [isCheckingUpdate]);
}, [isCheckingUpdate, useLatestBranch]);
const handleCopyToClipboard = useCallback(() => {
const debugInfo = {
@ -311,14 +303,17 @@ export default function DebugTab() {
responseTime: provider.responseTime,
url: provider.url,
})),
Version: versionHash,
Version: {
hash: versionHash.slice(0, 7),
branch: useLatestBranch ? 'main' : 'stable'
},
Timestamp: new Date().toISOString(),
};
navigator.clipboard.writeText(JSON.stringify(debugInfo, null, 2)).then(() => {
toast.success('Debug information copied to clipboard!');
});
}, [activeProviders, systemInfo]);
}, [activeProviders, systemInfo, useLatestBranch]);
return (
<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';
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) => {
enableDebugMode(enabled);
@ -14,9 +14,18 @@ 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="mb-6">
<h3 className="text-lg font-medium text-bolt-elements-textPrimary mb-4">Optional Features</h3>
<div className="flex items-center justify-between mb-2">
<span className="text-bolt-elements-textPrimary">Debug Features</span>
<Switch className="ml-auto" checked={debug} onCheckedChange={handleToggle} />
<div className="space-y-4">
<div className="flex items-center justify-between">
<span className="text-bolt-elements-textPrimary">Debug Features</span>
<Switch className="ml-auto" checked={debug} onCheckedChange={handleToggle} />
</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>

View File

@ -5,6 +5,7 @@ import {
isLocalModelsEnabled,
LOCAL_PROVIDERS,
providersStore,
useLatestBranch,
} from '~/lib/stores/settings';
import { useCallback, useEffect, useState } from 'react';
import Cookies from 'js-cookie';
@ -16,6 +17,7 @@ export function useSettings() {
const debug = useStore(isDebugMode);
const eventLogs = useStore(isEventLogsEnabled);
const isLocalModel = useStore(isLocalModelsEnabled);
const useLatest = useStore(useLatestBranch);
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
// reading values from cookies on mount
@ -60,6 +62,13 @@ export function useSettings() {
if (savedLocalModels) {
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
@ -111,6 +120,12 @@ export function useSettings() {
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 {
providers,
activeProviders,
@ -121,5 +136,7 @@ export function useSettings() {
enableEventLogs,
isLocalModel,
enableLocalModels,
useLatestBranch: useLatest,
enableLatestBranch,
};
}

View File

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