Prevent queries in workflow overriding default queries

https://github.com/github/codeql-action/pull/127#pullrequestreview-463207781
This commit is contained in:
Sam Partington 2020-08-24 14:33:02 +01:00
parent 517d9fad41
commit c6f02973ac
6 changed files with 68 additions and 82 deletions

36
lib/config-utils.js generated
View file

@ -350,6 +350,12 @@ async function getDefaultConfig() {
const languages = await getLanguages();
const queries = {};
await addDefaultQueries(languages, queries);
const queryUses = core.getInput('queries');
if (queryUses) {
queryUses.split(',').forEach(async (query) => {
await parseQueryUses('', languages, queries, query);
});
}
return {
languages: languages,
queries: queries,
@ -402,7 +408,15 @@ async function loadConfig(configFile) {
if (!disableDefaultQueries) {
await addDefaultQueries(languages, queries);
}
if (QUERIES_PROPERTY in parsedYAML) {
// If queries were provided using `with` in the action configuration,
// they should take precedence over the queries in the config file
const queryUses = core.getInput('queries');
if (queryUses) {
queryUses.split(',').forEach(async (query) => {
await parseQueryUses(configFile, languages, queries, query);
});
}
else if (QUERIES_PROPERTY in parsedYAML) {
if (!(parsedYAML[QUERIES_PROPERTY] instanceof Array)) {
throw new Error(getQueriesInvalid(configFile));
}
@ -460,12 +474,6 @@ async function initConfig() {
else {
config = await loadConfig(configFile);
}
// If queries were provided using `with` in the action configuration,
// they should take precedence over the queries in the config file
const queryUses = core.getInput('queries');
if (queryUses) {
config = await updateConfigWithQueries(config, queryUses, configFile);
}
// Save the config so we can easily access it again in the future
await saveConfig(config);
return config;
@ -478,20 +486,6 @@ function isLocal(configPath) {
}
return (configPath.indexOf("@") === -1);
}
async function updateConfigWithQueries(config, queryUses, configPath) {
if (isLocal(configPath)) {
// Treat the config file as relative to the workspace
const workspacePath = util.getRequiredEnvParam('GITHUB_WORKSPACE');
configPath = path.resolve(workspacePath, configPath);
}
const languages = await getLanguages();
const queries = {};
queryUses.split(',').forEach(async (query) => {
await parseQueryUses(configPath, languages, queries, query);
});
config.queries = queries;
return config;
}
function getLocalConfig(configFile, workspacePath) {
// Error if the config file is now outside of the workspace
if (!(configFile + path.sep).startsWith(workspacePath + path.sep)) {