- introduce capability to define the Configuration via the build yml without the requirement of a file
- this also allows to generate changelogs without the need to chech-out
This commit is contained in:
+13
-5
@@ -1,11 +1,13 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import {
|
||||
parseConfiguration,
|
||||
resolveConfiguration,
|
||||
retrieveRepositoryPath,
|
||||
writeOutput
|
||||
} from './utils'
|
||||
import {ReleaseNotesBuilder} from './releaseNotesBuilder'
|
||||
import {Configuration} from './configuration'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
core.setOutput('failed', false) // mark the action not failed by default
|
||||
@@ -17,11 +19,17 @@ async function run(): Promise<void> {
|
||||
const repositoryPath = retrieveRepositoryPath(inputPath)
|
||||
|
||||
// read in configuration file if possible
|
||||
const configurationFile: string = core.getInput('configuration')
|
||||
const configuration = resolveConfiguration(
|
||||
repositoryPath,
|
||||
configurationFile
|
||||
)
|
||||
let configuration: Configuration | undefined = undefined
|
||||
const configurationJson: string = core.getInput('configurationJson', {
|
||||
trimWhitespace: true
|
||||
})
|
||||
if (configurationJson) {
|
||||
configuration = parseConfiguration(configurationJson)
|
||||
}
|
||||
if (!configuration) {
|
||||
const configurationFile: string = core.getInput('configuration')
|
||||
configuration = resolveConfiguration(repositoryPath, configurationFile)
|
||||
}
|
||||
|
||||
// read in repository inputs
|
||||
const baseUrl = core.getInput('baseUrl')
|
||||
|
||||
+17
-9
@@ -67,24 +67,32 @@ export function resolveConfiguration(
|
||||
/**
|
||||
* Reads in the configuration from the JSON file
|
||||
*/
|
||||
function readConfiguration(filename: string): Configuration | null {
|
||||
let rawdata: string
|
||||
function readConfiguration(filename: string): Configuration | undefined {
|
||||
try {
|
||||
rawdata = fs.readFileSync(filename, 'utf8')
|
||||
const rawdata = fs.readFileSync(filename, 'utf8')
|
||||
if (rawdata) {
|
||||
return parseConfiguration(rawdata)
|
||||
}
|
||||
} catch (error) {
|
||||
core.info(
|
||||
`⚠️ Configuration provided, but it couldn't be found. Fallback to Defaults.`
|
||||
)
|
||||
return null
|
||||
core.debug(`Failed to load configuration due to: ${error}`)
|
||||
}
|
||||
core.info(
|
||||
`⚠️ Configuration provided, but it couldn't be found. Fallback to Defaults.`
|
||||
)
|
||||
return undefined
|
||||
}
|
||||
/**
|
||||
* Parses the configuration from the JSON file
|
||||
*/
|
||||
export function parseConfiguration(config: string): Configuration | undefined {
|
||||
try {
|
||||
const configurationJSON: Configuration = JSON.parse(rawdata)
|
||||
const configurationJSON: Configuration = JSON.parse(config)
|
||||
return configurationJSON
|
||||
} catch (error) {
|
||||
core.info(
|
||||
`⚠️ Configuration provided, but it couldn't be parsed. Fallback to Defaults.`
|
||||
)
|
||||
return null
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user