Merge branch 'main' into update-bundle/codeql-bundle-20230428

This commit is contained in:
Dave Bartolomeo 2023-05-03 19:02:27 -04:00 committed by GitHub
commit 33461954a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 402 additions and 55 deletions

View file

@ -105,11 +105,12 @@ test("load empty config", async (t) => {
undefined,
undefined,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -130,7 +131,7 @@ test("load empty config", async (t) => {
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -176,11 +177,12 @@ test("loading config saves config", async (t) => {
undefined,
undefined,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -214,11 +216,12 @@ test("load input outside of workspace", async (t) => {
undefined,
"../input",
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
getCachedCodeQL(),
tmpDir,
@ -254,11 +257,12 @@ test("load non-local input with invalid repo syntax", async (t) => {
undefined,
configFile,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
getCachedCodeQL(),
tmpDir,
@ -295,11 +299,12 @@ test("load non-existent input", async (t) => {
undefined,
configFile,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
getCachedCodeQL(),
tmpDir,
@ -402,11 +407,12 @@ test("load non-empty input", async (t) => {
undefined,
configFilePath,
undefined,
undefined,
false,
false,
"my-artifact",
"my-db",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -473,11 +479,12 @@ test("Default queries are used", async (t) => {
undefined,
configFilePath,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -552,11 +559,12 @@ test("Queries can be specified in config file", async (t) => {
undefined,
configFilePath,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -630,11 +638,12 @@ test("Queries from config file can be overridden in workflow file", async (t) =>
undefined,
configFilePath,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -706,11 +715,12 @@ test("Queries in workflow file can be used in tandem with the 'disable default q
undefined,
configFilePath,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -773,11 +783,12 @@ test("Multiple queries can be specified in workflow file, no config file require
undefined,
undefined,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -861,11 +872,12 @@ test("Queries in workflow file can be added to the set of queries without overri
undefined,
configFilePath,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -913,6 +925,181 @@ test("Queries in workflow file can be added to the set of queries without overri
});
});
test("Queries can be specified using config input", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
const configInput = `
name: my config
queries:
- uses: ./foo
packs:
javascript:
- a/b@1.2.3
python:
- c/d@1.2.3
`;
fs.mkdirSync(path.join(tmpDir, "foo"));
const resolveQueriesArgs: Array<{
queries: string[];
extraSearchPath: string | undefined;
}> = [];
const codeQL = setCodeQL({
async resolveQueries(
queries: string[],
extraSearchPath: string | undefined
) {
resolveQueriesArgs.push({ queries, extraSearchPath });
return queriesToResolvedQueryForm(queries);
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});
// Only JS, python packs will be ignored
const languages = "javascript";
const config = await configUtils.initConfig(
languages,
undefined,
undefined,
undefined,
undefined,
undefined,
configInput,
false,
false,
"",
"",
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatures([]),
getRunnerLogger(true)
);
// Check resolveQueries was called correctly
// It'll be called once for the default queries
// and once for `./foo` from the config file.
t.deepEqual(resolveQueriesArgs.length, 2);
t.deepEqual(resolveQueriesArgs[1].queries.length, 1);
t.true(resolveQueriesArgs[1].queries[0].endsWith(`${path.sep}foo`));
t.deepEqual(config.packs as unknown, {
[Language.javascript]: ["a/b@1.2.3"],
});
// Now check that the end result contains the default queries and the query from config
t.deepEqual(config.queries["javascript"].builtin.length, 1);
t.deepEqual(config.queries["javascript"].custom.length, 1);
t.true(
config.queries["javascript"].builtin[0].endsWith(
"javascript-code-scanning.qls"
)
);
t.true(
config.queries["javascript"].custom[0].queries[0].endsWith(
`${path.sep}foo`
)
);
});
});
test("Using config input and file together, config input should be used.", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
process.env["RUNNER_TEMP"] = tmpDir;
process.env["GITHUB_WORKSPACE"] = tmpDir;
const inputFileContents = `
name: my config
queries:
- uses: ./foo_file`;
const configFilePath = createConfigFile(inputFileContents, tmpDir);
const configInput = `
name: my config
queries:
- uses: ./foo
packs:
javascript:
- a/b@1.2.3
python:
- c/d@1.2.3
`;
fs.mkdirSync(path.join(tmpDir, "foo"));
const resolveQueriesArgs: Array<{
queries: string[];
extraSearchPath: string | undefined;
}> = [];
const codeQL = setCodeQL({
async resolveQueries(
queries: string[],
extraSearchPath: string | undefined
) {
resolveQueriesArgs.push({ queries, extraSearchPath });
return queriesToResolvedQueryForm(queries);
},
async packDownload(): Promise<PackDownloadOutput> {
return { packs: [] };
},
});
// Only JS, python packs will be ignored
const languages = "javascript";
const config = await configUtils.initConfig(
languages,
undefined,
undefined,
undefined,
undefined,
configFilePath,
configInput,
false,
false,
"",
"",
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
gitHubVersion,
sampleApiDetails,
createFeatures([]),
getRunnerLogger(true)
);
// Check resolveQueries was called correctly
// It'll be called once for the default queries
// and once for `./foo` from the config file.
t.deepEqual(resolveQueriesArgs.length, 2);
t.deepEqual(resolveQueriesArgs[1].queries.length, 1);
t.true(resolveQueriesArgs[1].queries[0].endsWith(`${path.sep}foo`));
t.deepEqual(config.packs as unknown, {
[Language.javascript]: ["a/b@1.2.3"],
});
// Now check that the end result contains the default queries and the query from config
t.deepEqual(config.queries["javascript"].builtin.length, 1);
t.deepEqual(config.queries["javascript"].custom.length, 1);
t.true(
config.queries["javascript"].builtin[0].endsWith(
"javascript-code-scanning.qls"
)
);
t.true(
config.queries["javascript"].custom[0].queries[0].endsWith(
`${path.sep}foo`
)
);
});
});
test("Invalid queries in workflow file handled correctly", async (t) => {
return await util.withTmpDir(async (tmpDir) => {
const queries = "foo/bar@v1@v3";
@ -943,11 +1130,12 @@ test("Invalid queries in workflow file handled correctly", async (t) => {
undefined,
undefined,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -1015,11 +1203,12 @@ test("API client used when reading remote config", async (t) => {
undefined,
configFile,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -1046,11 +1235,12 @@ test("Remote config handles the case where a directory is provided", async (t) =
undefined,
repoReference,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
getCachedCodeQL(),
tmpDir,
@ -1085,11 +1275,12 @@ test("Invalid format of remote config handled correctly", async (t) => {
undefined,
repoReference,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
getCachedCodeQL(),
tmpDir,
@ -1128,11 +1319,12 @@ test("No detected languages", async (t) => {
undefined,
undefined,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -1160,11 +1352,12 @@ test("Unknown languages", async (t) => {
undefined,
undefined,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
getCachedCodeQL(),
tmpDir,
@ -1217,11 +1410,12 @@ test("Config specifies packages", async (t) => {
undefined,
configFile,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -1278,6 +1472,7 @@ test("Config specifies packages for multiple languages", async (t) => {
undefined,
configFile,
undefined,
undefined,
false,
false,
"",
@ -1350,11 +1545,12 @@ function doInvalidInputTest(
undefined,
configFile,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,
@ -1934,11 +2130,12 @@ const mlPoweredQueriesMacro = test.macro({
undefined,
undefined,
undefined,
undefined,
false,
false,
"",
"",
{ owner: "github", repo: "example " },
{ owner: "github", repo: "example" },
tmpDir,
codeQL,
tmpDir,

View file

@ -1690,6 +1690,7 @@ export async function initConfig(
registriesInput: string | undefined,
configFile: string | undefined,
dbLocation: string | undefined,
configInput: string | undefined,
trapCachingEnabled: boolean,
debugMode: boolean,
debugArtifactName: string,
@ -1705,6 +1706,18 @@ export async function initConfig(
): Promise<Config> {
let config: Config;
// if configInput is set, it takes precedence over configFile
if (configInput) {
if (configFile) {
logger.warning(
`Both a config file and config input were provided. Ignoring config file.`
);
}
configFile = path.resolve(workspacePath, "user-config-from-action.yml");
fs.writeFileSync(configFile, configInput);
logger.debug(`Using config from action input: ${configFile}`);
}
// If no config file was provided create an empty one
if (!configFile) {
logger.debug("No configuration file was provided");

View file

@ -254,6 +254,7 @@ async function run() {
registriesInput,
getOptionalInput("config-file"),
getOptionalInput("db-location"),
getOptionalInput("config"),
getTrapCachingEnabled(),
// Debug mode is enabled if:
// - The `init` Action is passed `debug: true`.

View file

@ -57,6 +57,7 @@ export async function initConfig(
registriesInput: string | undefined,
configFile: string | undefined,
dbLocation: string | undefined,
configInput: string | undefined,
trapCachingEnabled: boolean,
debugMode: boolean,
debugArtifactName: string,
@ -78,6 +79,7 @@ export async function initConfig(
registriesInput,
configFile,
dbLocation,
configInput,
trapCachingEnabled,
debugMode,
debugArtifactName,
@ -107,7 +109,6 @@ export async function runInit(
logger: Logger
): Promise<TracerConfig | undefined> {
fs.mkdirSync(config.dbLocation, { recursive: true });
try {
// When parsing the codeql config in the CLI, we have not yet created the qlconfig file.
// So, create it now.