- introduce new API allowing to write changelog directly to result file

- introduce test case for writing a file
This commit is contained in:
Mike Penz
2020-12-30 17:49:41 +01:00
parent 9a0355af98
commit a463f188c1
7 changed files with 13179 additions and 5 deletions
+12 -1
View File
@@ -1,5 +1,9 @@
import * as core from '@actions/core'
import {retrieveRepositoryPath, resolveConfiguration} from './utils'
import {
retrieveRepositoryPath,
resolveConfiguration,
writeOutput
} from './utils'
import * as github from '@actions/github'
import {ReleaseNotesBuilder} from './releaseNotesBuilder'
@@ -43,6 +47,13 @@ async function run(): Promise<void> {
).build()
core.setOutput('changelog', result)
// write the result in changelog to file if possible
const outputFile: string = core.getInput('outputFile')
if (outputFile !== '') {
core.debug(`Enabled writing the changelog to disk`)
writeOutput(repositoryPath, outputFile, result)
}
} catch (error) {
core.setFailed(error.message)
}
+19
View File
@@ -111,3 +111,22 @@ export function directoryExistsSync(
throw new Error(`Directory '${inputPath}' does not exist`)
}
/**
* Writes the changelog to the given the file
*/
export function writeOutput(
githubWorkspacePath: string,
outputFile: string,
changelog: string | null
): void {
if (outputFile && changelog) {
const outputPath = path.resolve(githubWorkspacePath, outputFile)
core.debug(`outputPath = '${outputPath}'`)
try {
fs.writeFileSync(outputPath, changelog)
} catch (error) {
core.warning(`⚠️ Could not write the file to disk - ${error.message}`)
}
}
}