mirror of
https://github.com/github/codeql-action.git
synced 2026-05-07 22:30:44 +00:00
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:
+64
-14
@@ -14,32 +14,82 @@ test('download codeql bundle cache', async t => {
|
||||
|
||||
await util.withTmpDir(async tmpDir => {
|
||||
const versions = ['20200601', '20200610'];
|
||||
const plVersions = ['linux64-cpp', undefined];
|
||||
|
||||
for (let i = 0; i < versions.length; i++) {
|
||||
const version = versions[i];
|
||||
for (let i=0; i < versions.length; i++) {
|
||||
for (let j=0; j < plVersions.length; j++) {
|
||||
const version = versions[i];
|
||||
const plVersion = plVersions[j];
|
||||
const pkg = plVersion ? `codeql-${plVersion}.tar.gz` : `codeql-bundle.tar.gz`
|
||||
|
||||
nock('https://example.com')
|
||||
.get(`/download/codeql-bundle-${version}/codeql-bundle.tar.gz`)
|
||||
nock('https://example.com')
|
||||
.get(`/download/codeql-bundle-${version}/${pkg}`)
|
||||
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`));
|
||||
|
||||
await codeql.setupCodeQL(
|
||||
`https://example.com/download/codeql-bundle-${version}/codeql-bundle.tar.gz`,
|
||||
'token',
|
||||
'https://github.example.com',
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
'runner',
|
||||
getRunnerLogger(true));
|
||||
await codeql.setupCodeQL(
|
||||
`https://example.com/download/codeql-bundle-${version}/codeql-bundle.tar.gz`,
|
||||
plVersion,
|
||||
'token',
|
||||
'https://github.example.com',
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
'runner',
|
||||
getRunnerLogger(true));
|
||||
|
||||
t.assert(toolcache.find('CodeQL', `0.0.0-${version}`));
|
||||
const toolcacheVersion = plVersion ? `0.0.0-${version}-${plVersion}` : `0.0.0-${version}`;
|
||||
console.debug(toolcacheVersion)
|
||||
t.assert(toolcache.find('CodeQL', toolcacheVersion), `Looking for ${toolcacheVersion} - ${plVersion}`);
|
||||
}
|
||||
}
|
||||
|
||||
const cachedVersions = toolcache.findAllVersions('CodeQL');
|
||||
|
||||
t.is(cachedVersions.length, 2);
|
||||
t.is(cachedVersions.length, 4);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('use codeql bundle cache if pl version is not available', async t => {
|
||||
// If we look for a pl version but find in cache the bundle, we use the bundle
|
||||
await util.withTmpDir(async tmpDir => {
|
||||
const version = '20200601';
|
||||
const plVersion = 'linux64-cpp';
|
||||
|
||||
nock('https://example.com')
|
||||
.get(`/download/codeql-bundle-${version}/codeql-bundle.tar.gz`)
|
||||
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`));
|
||||
|
||||
await codeql.setupCodeQL(
|
||||
`https://example.com/download/codeql-bundle-${version}/codeql-bundle.tar.gz`,
|
||||
undefined,
|
||||
'token',
|
||||
'https://github.example.com',
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
'runner',
|
||||
getRunnerLogger(true));
|
||||
|
||||
t.assert(toolcache.find('CodeQL', `0.0.0-${version}`));
|
||||
t.is(toolcache.findAllVersions('CodeQL').length, 1);
|
||||
|
||||
// Now try to request the plVersion, and see that we do not change the cache
|
||||
await codeql.setupCodeQL(
|
||||
`https://example.com/download/codeql-bundle-${version}/codeql-bundle.tar.gz`,
|
||||
plVersion,
|
||||
'token',
|
||||
'https://github.example.com',
|
||||
tmpDir,
|
||||
tmpDir,
|
||||
'runner',
|
||||
getRunnerLogger(true));
|
||||
|
||||
t.assert(toolcache.find('CodeQL', `0.0.0-${version}`));
|
||||
t.is(toolcache.findAllVersions('CodeQL').length, 1);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('parse codeql bundle url version', t => {
|
||||
|
||||
const tests = {
|
||||
|
||||
+40
-8
@@ -127,6 +127,7 @@ function getCodeQLActionRepository(mode: util.Mode): string {
|
||||
}
|
||||
|
||||
async function getCodeQLBundleDownloadURL(
|
||||
bundleName: string,
|
||||
githubAuth: string,
|
||||
githubUrl: string,
|
||||
mode: util.Mode,
|
||||
@@ -158,7 +159,7 @@ async function getCodeQLBundleDownloadURL(
|
||||
tag: CODEQL_BUNDLE_VERSION
|
||||
});
|
||||
for (let asset of release.data.assets) {
|
||||
if (asset.name === CODEQL_BUNDLE_NAME) {
|
||||
if (asset.name === bundleName) {
|
||||
logger.info(`Found CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} with URL ${asset.url}.`);
|
||||
return asset.url;
|
||||
}
|
||||
@@ -193,6 +194,7 @@ async function toolcacheDownloadTool(
|
||||
|
||||
export async function setupCodeQL(
|
||||
codeqlURL: string | undefined,
|
||||
plVersion: string | undefined,
|
||||
githubAuth: string,
|
||||
githubUrl: string,
|
||||
tempDir: string,
|
||||
@@ -207,15 +209,44 @@ export async function setupCodeQL(
|
||||
process.env['RUNNER_TOOL_CACHE'] = toolsDir;
|
||||
|
||||
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 = toolcache.find('CodeQL', codeqlURLVersion);
|
||||
if (codeqlFolder) {
|
||||
logger.debug(`CodeQL found in cache ${codeqlFolder}`);
|
||||
} else {
|
||||
if (!codeqlURL) {
|
||||
codeqlURL = await getCodeQLBundleDownloadURL(githubAuth, githubUrl, mode, logger);
|
||||
let codeqlFolder;
|
||||
|
||||
logger.debug(`PL Version ${plVersion}`);
|
||||
if (plVersion) {
|
||||
|
||||
codeqlFolder = toolcache.find('CodeQL', `${codeqlURLVersion}-${plVersion}`);
|
||||
if (codeqlFolder) {
|
||||
logger.debug(`CodeQL found in cache ${codeqlFolder}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!codeqlFolder) {
|
||||
codeqlFolder = toolcache.find('CodeQL', codeqlURLVersion);
|
||||
if (codeqlFolder) {
|
||||
logger.debug(`CodeQL found in cache ${codeqlFolder}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!codeqlFolder) {
|
||||
const codeqlToolcacheVersion = plVersion ? `${codeqlURLVersion}-${plVersion}`: codeqlURLVersion;
|
||||
logger.debug(`CodeQL not found in cache`);
|
||||
if (!codeqlURL) {
|
||||
let pkgName = plVersion ? CODEQL_BUNDLE_NAME.replace("-bundle", `-${plVersion}`) : CODEQL_BUNDLE_NAME; // TODO : Maybe move template a constant?
|
||||
codeqlURL = await getCodeQLBundleDownloadURL(pkgName, githubAuth, githubUrl, mode, logger);
|
||||
}
|
||||
else if (plVersion) {
|
||||
let pkgName = CODEQL_BUNDLE_NAME.replace("-bundle", `-${plVersion}`)
|
||||
codeqlURL = codeqlURL.replace(CODEQL_BUNDLE_NAME, pkgName)
|
||||
}
|
||||
logger.debug(`Using CodeQL URL: ${codeqlURL}`);
|
||||
|
||||
const headers: IHeaders = {accept: 'application/octet-stream'};
|
||||
// We only want to provide an authorization header if we are downloading
|
||||
@@ -232,7 +263,8 @@ export async function setupCodeQL(
|
||||
logger.debug(`CodeQL bundle download to ${codeqlPath} complete.`);
|
||||
|
||||
const codeqlExtracted = await toolcache.extractTar(codeqlPath);
|
||||
codeqlFolder = await toolcache.cacheDir(codeqlExtracted, 'CodeQL', codeqlURLVersion);
|
||||
logger.debug(`Caching ${codeqlToolcacheVersion}`)
|
||||
codeqlFolder = await toolcache.cacheDir(codeqlExtracted, 'CodeQL', codeqlToolcacheVersion);
|
||||
}
|
||||
|
||||
let codeqlCmd = path.join(codeqlFolder, 'codeql', 'codeql');
|
||||
|
||||
@@ -22,6 +22,7 @@ export async function initCodeQL(
|
||||
logger.startGroup('Setup CodeQL tools');
|
||||
const codeql = await setupCodeQL(
|
||||
codeqlURL,
|
||||
undefined, // MG: FIXME
|
||||
githubAuth,
|
||||
githubUrl,
|
||||
tempDir,
|
||||
|
||||
Reference in New Issue
Block a user