Skip to content

Commit d72e0db

Browse files
committed
Adds minimum version checking for cli proxy
1 parent 06e50ee commit d72e0db

2 files changed

Lines changed: 69 additions & 18 deletions

File tree

src/env/node/gk/cli/integration.ts

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,12 @@ export class GkCliIntegrationProvider implements Disposable {
178178
let forceInstall = false;
179179
const cliInstall = this.container.storage.getScoped('gk:cli:install');
180180
if (cliInstall?.status === 'completed') {
181-
let currentCoreVersion = await this.getCliCoreVersion();
182-
const minimumVersion = await this.container.productConfig.getCliMinimumVersion();
183-
if (!currentCoreVersion || satisfies(fromString(currentCoreVersion), `< ${minimumVersion}`)) {
184-
Logger.log(`CLI core version ${currentCoreVersion ?? 'unknown'} is outdated, forcing reinstall`);
181+
const { needsUpdate, core, proxy } = await this.checkCliUpdateRequired();
182+
let currentCoreVersion = core;
183+
if (needsUpdate !== undefined) {
184+
Logger.log(
185+
`CLI ${needsUpdate} version ${(needsUpdate === 'core' ? currentCoreVersion : proxy) ?? 'unknown'} is outdated, forcing reinstall`,
186+
);
185187
forceInstall = true;
186188
} else {
187189
// Only update if GitLens extension version has changed since last check, to avoid unnecessary update checks
@@ -884,20 +886,61 @@ export class GkCliIntegrationProvider implements Disposable {
884886
}
885887

886888
@log()
887-
private async getCliCoreVersion(force = false): Promise<string | undefined> {
889+
private async checkCliUpdateRequired(): Promise<{
890+
needsUpdate: 'core' | 'proxy' | undefined;
891+
core: string | undefined;
892+
proxy: string | undefined;
893+
}> {
888894
const scope = getLogScope();
889895

890-
if (force || this._cliCoreVersion == null) {
891-
try {
892-
const versions = await getCLIVersions();
893-
this._cliCoreVersion = versions?.core;
894-
} catch (ex) {
895-
Logger.error(ex, scope, 'Failed to get CLI version');
896+
try {
897+
const currentVersions = await getCLIVersions();
898+
if (currentVersions == null) {
896899
this._cliCoreVersion = undefined;
900+
return {
901+
needsUpdate: 'proxy',
902+
core: undefined,
903+
proxy: undefined,
904+
};
897905
}
906+
907+
const { core: currentCoreVersion, proxy: currentProxyVersion } = currentVersions;
908+
this._cliCoreVersion = currentCoreVersion;
909+
910+
const { core: minimumCoreVersion, proxy: minimumProxyVersion } =
911+
await this.container.productConfig.getCliMinimumVersions();
912+
913+
if (satisfies(fromString(currentProxyVersion), `< ${minimumProxyVersion}`)) {
914+
return {
915+
needsUpdate: 'proxy',
916+
core: currentCoreVersion,
917+
proxy: currentProxyVersion,
918+
};
919+
}
920+
921+
if (satisfies(fromString(currentCoreVersion), `< ${minimumCoreVersion}`)) {
922+
return {
923+
needsUpdate: 'core',
924+
core: currentCoreVersion,
925+
proxy: currentProxyVersion,
926+
};
927+
}
928+
929+
return {
930+
needsUpdate: undefined,
931+
core: currentCoreVersion,
932+
proxy: currentProxyVersion,
933+
};
934+
} catch (ex) {
935+
Logger.error(ex, scope, 'Failed to get CLI version');
936+
this._cliCoreVersion = undefined;
898937
}
899938

900-
return this._cliCoreVersion;
939+
return {
940+
needsUpdate: 'proxy',
941+
core: undefined,
942+
proxy: undefined,
943+
};
901944
}
902945
}
903946

src/plus/gk/productConfigProvider.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import type { ServerConnection } from './serverConnection.js';
1414
type Config = {
1515
promos: Promo[];
1616
cli: {
17-
minimumVersion: string;
17+
minimumCoreVersion: string;
18+
minimumProxyVersion: string;
1819
};
1920
};
2021

@@ -24,7 +25,8 @@ type ConfigJson = {
2425
promos?: PromoJson[];
2526
promosV2?: PromoV2Json[];
2627
cli?: {
27-
minimumVersion: string;
28+
minimumCoreVersion: string;
29+
minimumProxyVersion: string;
2830
};
2931
};
3032
type PromoJson = Replace<Promo, 'plan' | 'expiresOn' | 'startsOn', string | undefined> & {
@@ -61,7 +63,8 @@ const fallbackConfig: Config = {
6163
} satisfies Promo,
6264
],
6365
cli: {
64-
minimumVersion: '3.1.52',
66+
minimumCoreVersion: '3.1.52',
67+
minimumProxyVersion: '3.1.53',
6568
},
6669
} as const;
6770

@@ -149,8 +152,12 @@ export class ProductConfigProvider {
149152
return getApplicablePromo(promos, state, plan, location);
150153
}
151154

152-
async getCliMinimumVersion(): Promise<string> {
153-
return (await this.getConfig()).cli.minimumVersion;
155+
async getCliMinimumVersions(): Promise<{ core: string; proxy: string }> {
156+
const cli = (await this.getConfig()).cli;
157+
return {
158+
core: cli.minimumCoreVersion,
159+
proxy: cli.minimumProxyVersion,
160+
};
154161
}
155162

156163
private getConfig(): Promise<Config> {
@@ -242,7 +249,8 @@ function createConfigValidator(): Validator<ConfigJson> {
242249
});
243250

244251
const cliValidator = createValidator({
245-
minimumVersion: Is.String,
252+
minimumCoreVersion: Is.String,
253+
minimumProxyVersion: Is.String,
246254
});
247255

248256
return createValidator<ConfigJson>({

0 commit comments

Comments
 (0)