- introduce new API allowing to write changelog directly to result file
- introduce test case for writing a file
This commit is contained in:
+12
-1
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user