Add support for basic query overriding in action file itself

See https://github.com/github/dsp-code-scanning/issues/1446
This commit is contained in:
Sam Partington
2020-07-27 11:03:57 +01:00
parent 74268130c6
commit 95cef22589
6 changed files with 141 additions and 2 deletions

View File

@@ -599,6 +599,13 @@ export async function initConfig(): Promise<Config> {
config = await loadConfig(configFile);
}
// If queries were provided as 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;
@@ -613,6 +620,21 @@ function isLocal(configPath: string): boolean {
return (configPath.indexOf("@") === -1);
}
async function updateConfigWithQueries(config: Config, queryUses: string, configPath: string): Promise<Config> {
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 = {};
await parseQueryUses(configPath, languages, queries, queryUses);
config.queries = queries;
return config;
}
function getLocalConfig(configFile: string, workspacePath: string): UserConfig {
// Error if the config file is now outside of the workspace
if (!(configFile + path.sep).startsWith(workspacePath + path.sep)) {