Skip to content

Commit

Permalink
- add additional logs on handling of configs (e.g. identify which con…
Browse files Browse the repository at this point in the history
…fig was picked) - outline if no config was picked and defaults are used
  • Loading branch information
mikepenz authored Feb 26, 2023
1 parent 6f298fb commit 0ce8384
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,20 @@ async function run(): Promise<void> {
})
if (configurationJson) {
configJson = parseConfiguration(configurationJson)
if (configJson) {
core.info(`ℹ️ Retreived configuration via 'configurationJson'.`)
}
}
// read in the configuration from the file if possible
const configurationFile: string = core.getInput('configuration')
const configFile = resolveConfiguration(repositoryPath, configurationFile)
if (configFile) {
core.info(`ℹ️ Retreived configuration via 'configuration' (via file).`)
}

if (!configurationFile && !configFile) {
core.info(`ℹ️ No configuration provided. Using Defaults.`)
}

// merge configs, use default values from DefaultConfig on missing definition
const configuration = mergeConfiguration(configJson, configFile)
Expand Down
12 changes: 7 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@ export function failOrError(message: string | Error, failOnError: boolean): void
/**
* Retrieves the configuration given the file path, if not found it will fallback to the `DefaultConfiguration`
*/
export function resolveConfiguration(githubWorkspacePath: string, configurationFile: string): Configuration {
let configuration = DefaultConfiguration
export function resolveConfiguration(githubWorkspacePath: string, configurationFile: string): Configuration | undefined {
if (configurationFile) {
const configurationPath = path.resolve(githubWorkspacePath, configurationFile)
core.debug(`configurationPath = '${configurationPath}'`)
const providedConfiguration = readConfiguration(configurationPath)
if (providedConfiguration) {
configuration = providedConfiguration
const configuration = providedConfiguration
core.info(`ℹ️ Configuration successfully loaded.`)
if (core.isDebug()) {
core.debug(`configuration = ${JSON.stringify(configuration)}`)
}
return configuration
} else {
core.debug(`Configuration file could not be read.`)
}
} else {
core.info(`ℹ️ Configuration not provided. Using Defaults.`)
core.debug(`Configuration file not provided.`)
}
return configuration
return undefined
}

/**
Expand Down

0 comments on commit 0ce8384

Please sign in to comment.