Skip to content

Commit 109c875

Browse files
authored
Merge pull request #421 from jcreedcmu/jcreed/fix-release-asset-search
Download platform-specific releases if they are available.
2 parents ddf382d + 218a14a commit 109c875

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

extensions/ql-vscode/src/distribution.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,18 @@ class ExtensionSpecificDistributionManager {
297297
`but encountered an error: ${e}.`);
298298
}
299299

300-
const assetStream = await this.createReleasesApiConsumer().streamBinaryContentOfAsset(release.assets[0]);
300+
// Filter assets to the unique one that we require.
301+
const requiredAssetName = this.getRequiredAssetName();
302+
const assets = release.assets.filter(asset => asset.name === requiredAssetName);
303+
if (assets.length === 0) {
304+
throw new Error(`Invariant violation: chose a release to install that didn't have ${requiredAssetName}`);
305+
}
306+
if (assets.length > 1) {
307+
logger.log('WARNING: chose a release with more than one asset to install, found ' +
308+
assets.map(asset => asset.name).join(', '));
309+
}
310+
311+
const assetStream = await this.createReleasesApiConsumer().streamBinaryContentOfAsset(assets[0]);
301312
const tmpDirectory = await fs.mkdtemp(path.join(os.tmpdir(), "vscode-codeql"));
302313

303314
try {
@@ -354,21 +365,31 @@ class ExtensionSpecificDistributionManager {
354365
}
355366
}
356367

368+
/**
369+
* Get the name of the codeql cli installation we prefer to install, based on our current platform.
370+
*/
371+
private getRequiredAssetName(): string {
372+
if (os.platform() === 'linux') return 'codeql-linux64.zip';
373+
if (os.platform() === 'darwin') return 'codeql-osx64.zip';
374+
if (os.platform() === 'win32') return 'codeql-win64.zip';
375+
return 'codeql.zip';
376+
}
377+
357378
private async getLatestRelease(): Promise<Release> {
358-
return await this.createReleasesApiConsumer().getLatestRelease(
379+
const requiredAssetName = this.getRequiredAssetName();
380+
logger.log(`Searching for latest release including ${requiredAssetName}.`);
381+
return this.createReleasesApiConsumer().getLatestRelease(
359382
this._versionRange,
360383
this._config.includePrerelease,
361384
release => {
362-
// FIXME: Look for platform-specific codeql distribution if available
363-
// https://github.com/github/vscode-codeql/issues/417
364-
const matchingAssets = release.assets.filter(asset => asset.name === 'codeql.zip');
385+
const matchingAssets = release.assets.filter(asset => asset.name === requiredAssetName);
365386
if (matchingAssets.length === 0) {
366-
// For example, this could be a release with only platform-specific assets.
367-
logger.log("INFO: Ignoring a release with no assets named codeql.zip");
387+
// For example, this could be a release with no platform-specific assets.
388+
logger.log(`INFO: Ignoring a release with no assets named ${requiredAssetName}`);
368389
return false;
369390
}
370391
if (matchingAssets.length > 1) {
371-
logger.log("WARNING: Ignoring a release with more than one asset named codeql.zip");
392+
logger.log(`WARNING: Ignoring a release with more than one asset named ${requiredAssetName}`);
372393
return false;
373394
}
374395
return true;

0 commit comments

Comments
 (0)