mirror of
https://github.com/github/codeql-action.git
synced 2026-01-02 20:50:05 +08:00
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:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user