mirror of
https://github.com/github/codeql-action.git
synced 2026-05-08 14:50:21 +00:00
# This is a combination of 4 commits.
# This is the 1st commit message: 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. # The commit message #2 will be skipped: # add test # The commit message #3 will be skipped: # cleanup # The commit message #4 will be skipped: # linter
This commit is contained in:
Generated
+24
-10
@@ -14,11 +14,14 @@ const toolcache = __importStar(require("@actions/tool-cache"));
|
||||
const ava_1 = __importDefault(require("ava"));
|
||||
const nock_1 = __importDefault(require("nock"));
|
||||
const path = __importStar(require("path"));
|
||||
const sinon_1 = __importDefault(require("sinon"));
|
||||
const api = __importStar(require("./api-client"));
|
||||
const github = __importStar(require("@actions/github"));
|
||||
const codeql = __importStar(require("./codeql"));
|
||||
const languages_1 = require("./languages");
|
||||
const logging_1 = require("./logging");
|
||||
const testing_utils_1 = require("./testing-utils");
|
||||
const util = __importStar(require("./util"));
|
||||
const languages_1 = require("./languages");
|
||||
testing_utils_1.setupTests(ava_1.default);
|
||||
ava_1.default('download codeql bundle cache', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
@@ -27,20 +30,19 @@ ava_1.default('download codeql bundle cache', async (t) => {
|
||||
[languages_1.Language.cpp],
|
||||
[languages_1.Language.cpp, languages_1.Language.python] // Multi-language requires the full bundle
|
||||
];
|
||||
const platform = process.platform == 'win32' ? 'win64' :
|
||||
process.platform == 'linux' ? 'linux64' :
|
||||
process.platform == 'darwin' ? 'osx64' : undefined;
|
||||
const platform = process.platform === 'win32' ? 'win64' :
|
||||
process.platform === 'linux' ? 'linux64' :
|
||||
process.platform === 'darwin' ? 'osx64' : undefined;
|
||||
for (let i = 0; i < versions.length; i++) {
|
||||
for (let j = 0; j < languages.length; j++) {
|
||||
const version = versions[i];
|
||||
const plVersion = (languages[j].length == 1) ? `${platform}-${languages[j][0]}` : undefined;
|
||||
const plVersion = (languages[j].length === 1) ? `${platform}-${languages[j][0]}` : undefined;
|
||||
const pkg = plVersion ? `codeql-${plVersion}.tar.gz` : `codeql-bundle.tar.gz`;
|
||||
nock_1.default('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`, languages[j], 'token', 'https://github.example.com', tmpDir, tmpDir, 'runner', logging_1.getRunnerLogger(true));
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
@@ -64,10 +66,22 @@ ava_1.default('use codeql bundle cache if pl version is not available', async (t
|
||||
t.is(toolcache.findAllVersions('CodeQL').length, 1);
|
||||
});
|
||||
});
|
||||
// test('use larger bundles if smaller ones are unavailble', async t => {
|
||||
// // TODO: This should check the fallback behavior of getCodeQLBundleDownloadURL
|
||||
// t.fail()
|
||||
// });
|
||||
ava_1.default('use larger bundles if smaller ones are unavailble', async (t) => {
|
||||
// Mock the API client
|
||||
let client = new github.GitHub('123');
|
||||
const response = {
|
||||
data: { 'assets': [
|
||||
{ 'name': 'full-bundle', 'url': 'url/file.gz' },
|
||||
] },
|
||||
};
|
||||
let getReleaseByTagMock = sinon_1.default.stub(client.repos, "getReleaseByTag").resolves(response);
|
||||
sinon_1.default.stub(api, "getApiClient").value(() => client);
|
||||
// Setting this env is required by a dependency of getCodeQLBundleDownloadURL
|
||||
process.env['RUNNER_TEMP'] = "abc";
|
||||
let codeqlURL = await codeql.getCodeQLBundleDownloadURL(['small-bundle', 'full-bundle'], "", "", 'actions', logging_1.getRunnerLogger(true));
|
||||
t.deepEqual(codeqlURL, 'url/file.gz');
|
||||
t.assert(getReleaseByTagMock.called);
|
||||
});
|
||||
ava_1.default('parse codeql bundle url version', t => {
|
||||
const tests = {
|
||||
'20200601': '0.0.0-20200601',
|
||||
|
||||
Reference in New Issue
Block a user