Dont merge config lists
Co-authored-by: Henri Maurer<[email protected]> Co-authored-by: Federico Builes<[email protected]>
This commit is contained in:
co-authored by
Henri Maurer
Federico Builes
parent
3c73a622ba
commit
78565a954f
+7
-25
@@ -14,8 +14,11 @@ export async function readConfig(): Promise<ConfigurationOptions> {
|
||||
const configFile = getOptionalInput('config-file')
|
||||
if (configFile !== undefined) {
|
||||
const externalConfig = await readConfigFile(configFile)
|
||||
// TO DO check order of precedence
|
||||
return mergeConfigs(externalConfig, inlineConfig)
|
||||
|
||||
return ConfigurationOptionsSchema.parse({
|
||||
...externalConfig,
|
||||
...inlineConfig
|
||||
})
|
||||
}
|
||||
|
||||
return ConfigurationOptionsSchema.parse(inlineConfig)
|
||||
@@ -141,6 +144,8 @@ async function getRemoteConfig(configOpts: {
|
||||
[key: string]: string
|
||||
}): Promise<string> {
|
||||
try {
|
||||
// https://github.com/github/codeql-action/blob/main/init/action.yml#L59
|
||||
// external-repo-token
|
||||
const {data} = await octokitClient(
|
||||
'remote-config-repo-token',
|
||||
false
|
||||
@@ -162,26 +167,3 @@ async function getRemoteConfig(configOpts: {
|
||||
throw new Error('Error fetching remote config file')
|
||||
}
|
||||
}
|
||||
|
||||
function mergeConfigs(
|
||||
baseConfig: ConfigurationOptionsPartial,
|
||||
prioConfig: ConfigurationOptionsPartial
|
||||
): ConfigurationOptions {
|
||||
const mergedConfig: {[key: string]: unknown} = {...baseConfig}
|
||||
|
||||
for (const key of Object.keys(prioConfig) as (keyof typeof prioConfig)[]) {
|
||||
// based on the assumption that ConfigurationOptions values are either arrays or primitive types
|
||||
// former are merged, latter are overwritten
|
||||
if (key in mergedConfig && Array.isArray(mergedConfig[key])) {
|
||||
// casting to unknown[] needed. TS unable to auto infer
|
||||
mergedConfig[key] = [
|
||||
...(mergedConfig[key] as unknown[]),
|
||||
...(prioConfig[key] as unknown[])
|
||||
]
|
||||
} else {
|
||||
mergedConfig[key] = prioConfig[key]
|
||||
}
|
||||
}
|
||||
|
||||
return ConfigurationOptionsSchema.parse(mergedConfig)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user