Skip to content

Commit b7bfd9e

Browse files
committed
Add CLI version constraint for packaging
1 parent 25f0e3c commit b7bfd9e

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

extensions/ql-vscode/src/cli.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,11 @@ export class CliVersionConstraint {
11991199
*/
12001200
public static CLI_VERSION_WITH_OLD_EVAL_STATS = new SemVer('2.7.4');
12011201

1202+
/**
1203+
* CLI version where packaging was introduced.
1204+
*/
1205+
public static CLI_VERSION_WITH_PACKAGING = new SemVer('2.6.0');
1206+
12021207
constructor(private readonly cli: CodeQLCliServer) {
12031208
/**/
12041209
}
@@ -1250,4 +1255,8 @@ export class CliVersionConstraint {
12501255
async supportsOldEvalStats() {
12511256
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_OLD_EVAL_STATS);
12521257
}
1258+
1259+
async supportsPackaging() {
1260+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_PACKAGING);
1261+
}
12531262
}

extensions/ql-vscode/src/packaging.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CodeQLCliServer } from './cli';
1+
import { CliVersionConstraint, CodeQLCliServer } from './cli';
22
import {
33
getOnDiskWorkspaceFolders,
44
showAndLogErrorMessage,
@@ -30,6 +30,10 @@ export async function handleDownloadPacks(
3030
cliServer: CodeQLCliServer,
3131
progress: ProgressCallback,
3232
): Promise<void> {
33+
if (!(await cliServer.cliConstraints.supportsPackaging())) {
34+
throw new Error(`Packaging commands are not supported by this version of CodeQL. Please upgrade to v${CliVersionConstraint.CLI_VERSION_WITH_PACKAGING
35+
} or later.`);
36+
}
3337
progress({
3438
message: 'Choose packs to download',
3539
step: 1,
@@ -87,6 +91,10 @@ export async function handleInstallPacks(
8791
cliServer: CodeQLCliServer,
8892
progress: ProgressCallback,
8993
): Promise<void> {
94+
if (!(await cliServer.cliConstraints.supportsPackaging())) {
95+
throw new Error(`Packaging commands are not supported by this version of CodeQL. Please upgrade to v${CliVersionConstraint.CLI_VERSION_WITH_PACKAGING
96+
} or later.`);
97+
}
9098
progress({
9199
message: 'Choose packs to install',
92100
step: 1,

extensions/ql-vscode/src/vscode-tests/cli-integration/packaging.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'path';
55

66
import * as pq from 'proxyquire';
77

8-
import { CodeQLCliServer } from '../../cli';
8+
import { CliVersionConstraint, CodeQLCliServer } from '../../cli';
99
import { CodeQLExtensionInterface } from '../../extension';
1010
import { expect } from 'chai';
1111

@@ -40,7 +40,11 @@ describe('Packaging commands', function() {
4040
'Extension not initialized. Make sure cli is downloaded and installed properly.'
4141
);
4242
}
43-
43+
if (!(await cli.cliConstraints.supportsPackaging())) {
44+
console.log(`Packaging commands are not supported on CodeQL CLI v${CliVersionConstraint.CLI_VERSION_WITH_PACKAGING
45+
}. Skipping this test.`);
46+
this.skip();
47+
}
4448
progress = sandbox.spy();
4549
quickPickSpy = sandbox.stub(window, 'showQuickPick');
4650
inputBoxSpy = sandbox.stub(window, 'showInputBox');

0 commit comments

Comments
 (0)