Remove code to download packs
This commit is contained in:
parent
f65fc6a926
commit
4feb32a7ef
6 changed files with 3 additions and 374 deletions
|
|
@ -15,7 +15,6 @@ import { parseRepositoryNwo } from "./repository";
|
|||
import {
|
||||
setupTests,
|
||||
mockLanguagesInRepo as mockLanguagesInRepo,
|
||||
makeVersionInfo,
|
||||
} from "./testing-utils";
|
||||
import {
|
||||
GitHubVariant,
|
||||
|
|
@ -1042,174 +1041,6 @@ test(
|
|||
/"a-pack-without-a-scope" is not a valid pack/,
|
||||
);
|
||||
|
||||
test("downloadPacks-no-registries", async (t) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const packDownloadStub = sinon.stub();
|
||||
packDownloadStub.callsFake((packs) => ({
|
||||
packs,
|
||||
}));
|
||||
const codeQL = setCodeQL({
|
||||
packDownload: packDownloadStub,
|
||||
});
|
||||
const logger = getRunnerLogger(true);
|
||||
|
||||
// packs are supplied for go, java, and python
|
||||
// analyzed languages are java, javascript, and python
|
||||
await configUtils.downloadPacks(
|
||||
codeQL,
|
||||
[Language.javascript, Language.java, Language.python],
|
||||
{
|
||||
java: ["a", "b"],
|
||||
go: ["c", "d"],
|
||||
python: ["e", "f"],
|
||||
},
|
||||
sampleApiDetails,
|
||||
undefined, // registriesAuthTokens
|
||||
tmpDir,
|
||||
logger,
|
||||
);
|
||||
|
||||
// Expecting packs to be downloaded once for java and once for python
|
||||
t.deepEqual(packDownloadStub.callCount, 2);
|
||||
// no config file was created, so pass `undefined` as the config file path
|
||||
t.deepEqual(packDownloadStub.firstCall.args, [["a", "b"], undefined]);
|
||||
t.deepEqual(packDownloadStub.secondCall.args, [["e", "f"], undefined]);
|
||||
});
|
||||
});
|
||||
|
||||
test("downloadPacks-with-registries", async (t) => {
|
||||
// same thing, but this time include a registries block and
|
||||
// associated env vars
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
process.env.GITHUB_TOKEN = "not-a-token";
|
||||
process.env.CODEQL_REGISTRIES_AUTH = undefined;
|
||||
const logger = getRunnerLogger(true);
|
||||
|
||||
const registriesInput = yaml.dump([
|
||||
{
|
||||
// no slash
|
||||
url: "http://ghcr.io",
|
||||
packages: ["codeql/*", "codeql-testing/*"],
|
||||
token: "not-a-token",
|
||||
},
|
||||
{
|
||||
// with slash
|
||||
url: "https://containers.GHEHOSTNAME1/v2/",
|
||||
packages: "semmle/*",
|
||||
token: "still-not-a-token",
|
||||
},
|
||||
]);
|
||||
|
||||
// append a slash to the first url
|
||||
const registries = yaml.load(
|
||||
registriesInput,
|
||||
) as configUtils.RegistryConfigWithCredentials[];
|
||||
const expectedRegistries = registries.map((r, i) => ({
|
||||
packages: r.packages,
|
||||
url: i === 0 ? `${r.url}/` : r.url,
|
||||
}));
|
||||
|
||||
const expectedConfigFile = path.join(tmpDir, "qlconfig.yml");
|
||||
const packDownloadStub = sinon.stub();
|
||||
packDownloadStub.callsFake((packs, configFile: string) => {
|
||||
t.deepEqual(configFile, expectedConfigFile);
|
||||
// verify the env vars were set correctly
|
||||
t.deepEqual(process.env.GITHUB_TOKEN, sampleApiDetails.auth);
|
||||
t.deepEqual(
|
||||
process.env.CODEQL_REGISTRIES_AUTH,
|
||||
"http://ghcr.io=not-a-token,https://containers.GHEHOSTNAME1/v2/=still-not-a-token",
|
||||
);
|
||||
|
||||
// verify the config file contents were set correctly
|
||||
const config = yaml.load(fs.readFileSync(configFile, "utf8")) as {
|
||||
registries: configUtils.RegistryConfigNoCredentials[];
|
||||
};
|
||||
t.deepEqual(config.registries, expectedRegistries);
|
||||
return {
|
||||
packs,
|
||||
};
|
||||
});
|
||||
|
||||
const codeQL = setCodeQL({
|
||||
packDownload: packDownloadStub,
|
||||
getVersion: () => Promise.resolve(makeVersionInfo("2.10.5")),
|
||||
});
|
||||
|
||||
// packs are supplied for go, java, and python
|
||||
// analyzed languages are java, javascript, and python
|
||||
await configUtils.downloadPacks(
|
||||
codeQL,
|
||||
[Language.javascript, Language.java, Language.python],
|
||||
{
|
||||
java: ["a", "b"],
|
||||
go: ["c", "d"],
|
||||
python: ["e", "f"],
|
||||
},
|
||||
sampleApiDetails,
|
||||
registriesInput,
|
||||
tmpDir,
|
||||
logger,
|
||||
);
|
||||
|
||||
// Same packs are downloaded as in previous test
|
||||
t.deepEqual(packDownloadStub.callCount, 2);
|
||||
t.deepEqual(packDownloadStub.firstCall.args, [
|
||||
["a", "b"],
|
||||
expectedConfigFile,
|
||||
]);
|
||||
t.deepEqual(packDownloadStub.secondCall.args, [
|
||||
["e", "f"],
|
||||
expectedConfigFile,
|
||||
]);
|
||||
|
||||
// Verify that the env vars were unset.
|
||||
t.deepEqual(process.env.GITHUB_TOKEN, "not-a-token");
|
||||
t.deepEqual(process.env.CODEQL_REGISTRIES_AUTH, undefined);
|
||||
});
|
||||
});
|
||||
|
||||
test("downloadPacks-with-registries fails with invalid registries block", async (t) => {
|
||||
// same thing, but this time include a registries block and
|
||||
// associated env vars
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
process.env.GITHUB_TOKEN = "not-a-token";
|
||||
process.env.CODEQL_REGISTRIES_AUTH = "not-a-registries-auth";
|
||||
const logger = getRunnerLogger(true);
|
||||
|
||||
const registriesInput = yaml.dump([
|
||||
{
|
||||
// missing url property
|
||||
packages: ["codeql/*", "codeql-testing/*"],
|
||||
token: "not-a-token",
|
||||
},
|
||||
{
|
||||
url: "https://containers.GHEHOSTNAME1/v2/",
|
||||
packages: "semmle/*",
|
||||
token: "still-not-a-token",
|
||||
},
|
||||
]);
|
||||
|
||||
const codeQL = setCodeQL({
|
||||
getVersion: () => Promise.resolve(makeVersionInfo("2.10.4")),
|
||||
});
|
||||
await t.throwsAsync(
|
||||
async () => {
|
||||
return await configUtils.downloadPacks(
|
||||
codeQL,
|
||||
[Language.javascript, Language.java, Language.python],
|
||||
{},
|
||||
sampleApiDetails,
|
||||
registriesInput,
|
||||
tmpDir,
|
||||
logger,
|
||||
);
|
||||
},
|
||||
{ instanceOf: Error },
|
||||
"Invalid 'registries' input. Must be an array of objects with 'url' and 'packages' properties.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("no generateRegistries when registries is undefined", async (t) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const registriesInput = undefined;
|
||||
|
|
|
|||
|
|
@ -952,59 +952,6 @@ export async function getConfig(
|
|||
return JSON.parse(configString);
|
||||
}
|
||||
|
||||
export async function downloadPacks(
|
||||
codeQL: CodeQL,
|
||||
languages: Language[],
|
||||
packs: Packs,
|
||||
apiDetails: api.GitHubApiDetails,
|
||||
registriesInput: string | undefined,
|
||||
tempDir: string,
|
||||
logger: Logger,
|
||||
) {
|
||||
// This code path is only used when config parsing occurs in the Action.
|
||||
const { registriesAuthTokens, qlconfigFile } = await generateRegistries(
|
||||
registriesInput,
|
||||
tempDir,
|
||||
logger,
|
||||
);
|
||||
await wrapEnvironment(
|
||||
{
|
||||
GITHUB_TOKEN: apiDetails.auth,
|
||||
CODEQL_REGISTRIES_AUTH: registriesAuthTokens,
|
||||
},
|
||||
async () => {
|
||||
let numPacksDownloaded = 0;
|
||||
logger.startGroup("Downloading packs");
|
||||
for (const language of languages) {
|
||||
const packsWithVersion = packs[language];
|
||||
if (packsWithVersion?.length) {
|
||||
logger.info(`Downloading custom packs for ${language}`);
|
||||
const results = await codeQL.packDownload(
|
||||
packsWithVersion,
|
||||
qlconfigFile,
|
||||
);
|
||||
numPacksDownloaded += results.packs.length;
|
||||
logger.info(
|
||||
`Downloaded: ${results.packs
|
||||
.map((r) => `${r.name}@${r.version || "latest"}`)
|
||||
.join(", ")}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (numPacksDownloaded > 0) {
|
||||
logger.info(
|
||||
`Downloaded ${numPacksDownloaded} ${
|
||||
numPacksDownloaded === 1 ? "pack" : "packs"
|
||||
}`,
|
||||
);
|
||||
} else {
|
||||
logger.info("No packs to download");
|
||||
}
|
||||
logger.endGroup();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a `qlconfig.yml` file from the `registries` input.
|
||||
* This file is used by the CodeQL CLI to list the registries to use for each
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue