Add logic to download codeql platform-language pkg

* Add `bundleName` argument to `getCodeQLBundleDownloadURL`
* Add `languages` argument to `setupCodeQL`.

The logic now tries to find the platform-language pkg before defaulting
to the full bundle. We keep the toolcache clean by adding the pl version
to the tool version.
This commit is contained in:
Marco Gario
2020-09-09 13:53:11 +02:00
parent d3d7dd4600
commit 57b0b7fd1d
4 changed files with 80 additions and 23 deletions
Generated
+20 -11
View File
@@ -112,7 +112,20 @@ async function setupCodeQL(codeqlURL, languages, githubAuth, githubUrl, tempDir,
// be better to write our own implementation to use outside of actions.
process.env['RUNNER_TEMP'] = tempDir;
process.env['RUNNER_TOOL_CACHE'] = toolsDir;
// Compute package version
// The URL identifies the release version. E.g., codeql-20200901 .
// The plVersion identifies the platform-language combination of the package
// within the release. E.g., `linux64-cpp` in `codeql-linux64-cpp.tar.gz`.
// We expect the codeqlUrl (when given) to always point to the main bundle
// `codeql-bundle.tar.gz`
//
// The logic is as follows:
// - Always use the Toolcache if available.
// - If we would like a platform-language package, but have the
// full bundle in the cache, use that.
// - If codeqlURL is specified, use that.
// - If a single language is being analyzed, try to download the platform-language package.
// - If it is not available in the release assets, fallback to the full bundle
// - If multiple languages are being anlyzed, use the full bundle
let plVersion = undefined;
let platform;
if (process.platform === 'win32') {
@@ -131,11 +144,6 @@ async function setupCodeQL(codeqlURL, languages, githubAuth, githubUrl, tempDir,
plVersion = `${platform}-${languages[0]}`;
}
try {
// The URL identifies the release version. E.g., codeql-20200901 .
// The plVersion identifies the platform-language combination of the package
// within the release. E.g., `linux64-cpp` in `codeql-linux64-cpp.tar.gz`.
// We expect the codeqlUrl (when given) to always point to the main bundle
// `codeql-bundle.tar.gz`
const codeqlURLVersion = getCodeQLURLVersion(codeqlURL || `/${CODEQL_BUNDLE_VERSION}/`, logger);
let codeqlFolder;
logger.debug(`PL Version ${plVersion}`);
@@ -156,11 +164,12 @@ async function setupCodeQL(codeqlURL, languages, githubAuth, githubUrl, tempDir,
logger.debug(`CodeQL not found in cache`);
if (!codeqlURL) {
// Provide a few options, from smaller to bigger
const bundles = [
CODEQL_BUNDLE_NAME.replace("-bundle", `-bundle-${plVersion}`),
CODEQL_BUNDLE_NAME.replace("-bundle", `-bundle-${platform}`),
CODEQL_BUNDLE_NAME,
];
let bundles = [];
if (plVersion) {
bundles.push(CODEQL_BUNDLE_NAME.replace("-bundle", `-bundle-${plVersion}`));
}
bundles.push(CODEQL_BUNDLE_NAME.replace("-bundle", `-bundle-${platform}`));
bundles.push(CODEQL_BUNDLE_NAME);
codeqlURL = await getCodeQLBundleDownloadURL(bundles, githubAuth, githubUrl, mode, logger);
}
logger.debug(`Using CodeQL URL: ${codeqlURL}`);