Merge pull request #138 from mikepenz/feature/136
Support writing result changelog to file
This commit is contained in:
@@ -208,6 +208,7 @@ For advanced use cases additional settings can be provided to the action
|
||||
| **Input** | **Description** |
|
||||
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `configuration` | Relative path, to the `configuration.json` file, providing additional configurations |
|
||||
| `outputFile` | Optional relative path to a file to store the resulting changelog in. |
|
||||
| `owner` | The owner of the repository to generate the changelog for |
|
||||
| `repo` | Name of the repository we want to process |
|
||||
| `fromTag` | Defines the 'start' from where the changelog will consider merged pull requests |
|
||||
|
||||
+27
-1
@@ -1,6 +1,7 @@
|
||||
import * as path from 'path'
|
||||
import * as process from 'process'
|
||||
import * as cp from 'child_process'
|
||||
import * as fs from 'fs'
|
||||
|
||||
test('missing values should result in failure', () => {
|
||||
process.env['GITHUB_WORKSPACE'] = '.'
|
||||
@@ -17,7 +18,7 @@ test('missing values should result in failure', () => {
|
||||
}
|
||||
})
|
||||
|
||||
test('missing values should result in failure', () => {
|
||||
test('complete input should succeed', () => {
|
||||
process.env['GITHUB_WORKSPACE'] = '.'
|
||||
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
|
||||
process.env['INPUT_OWNER'] = 'mikepenz'
|
||||
@@ -31,4 +32,29 @@ test('missing values should result in failure', () => {
|
||||
}
|
||||
const result = cp.execSync(`node ${ip}`, options).toString()
|
||||
// should succeed
|
||||
expect(result).toBeDefined()
|
||||
})
|
||||
|
||||
test('should write result to file', () => {
|
||||
process.env['GITHUB_WORKSPACE'] = '.'
|
||||
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
|
||||
process.env['INPUT_OWNER'] = 'mikepenz'
|
||||
process.env['INPUT_REPO'] = 'release-changelog-builder-action'
|
||||
process.env['INPUT_FROMTAG'] = 'v0.3.0'
|
||||
process.env['INPUT_TOTAG'] = 'v0.5.0'
|
||||
process.env['INPUT_OUTPUTFILE'] = 'test.md'
|
||||
|
||||
const ip = path.join(__dirname, '..', 'lib', 'main.js')
|
||||
const options: cp.ExecSyncOptions = {
|
||||
env: process.env
|
||||
}
|
||||
const result = cp.execSync(`node ${ip}`, options).toString()
|
||||
// should succeed
|
||||
expect(result).toBeDefined()
|
||||
|
||||
const readOutput = fs.readFileSync("test.md")
|
||||
|
||||
fs.unlinkSync("test.md")
|
||||
|
||||
expect(readOutput.toString()).not.toBe('')
|
||||
})
|
||||
|
||||
@@ -23,6 +23,8 @@ inputs:
|
||||
failOnError:
|
||||
description: 'Defines if the action should result in a build failure, if an error was discovered'
|
||||
default: "false"
|
||||
outputFile:
|
||||
description: 'If defined, the changelog will get written to this file. (relative to the checkout dir)'
|
||||
token:
|
||||
description: 'Defines the token to use to execute the git API requests with, uses `env.GITHUB_TOKEN` by default'
|
||||
outputs:
|
||||
|
||||
+23
-1
@@ -331,6 +331,12 @@ function run() {
|
||||
const failOnError = core.getInput('failOnError') === 'true';
|
||||
const result = yield new releaseNotesBuilder_1.ReleaseNotesBuilder(token, repositoryPath, owner, repo, fromTag, toTag, failOnError, ignorePreReleases, configuration).build();
|
||||
core.setOutput('changelog', result);
|
||||
// write the result in changelog to file if possible
|
||||
const outputFile = core.getInput('outputFile');
|
||||
if (outputFile !== "") {
|
||||
core.debug(`Enabled writing the changelog to disk`);
|
||||
utils_1.writeOutput(repositoryPath, outputFile, result);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
@@ -1181,7 +1187,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.directoryExistsSync = exports.resolveConfiguration = exports.failOrError = exports.retrieveRepositoryPath = void 0;
|
||||
exports.writeOutput = exports.directoryExistsSync = exports.resolveConfiguration = exports.failOrError = exports.retrieveRepositoryPath = void 0;
|
||||
const fs = __importStar(__webpack_require__(5747));
|
||||
const configuration_1 = __webpack_require__(5527);
|
||||
const core = __importStar(__webpack_require__(2186));
|
||||
@@ -1277,6 +1283,22 @@ function directoryExistsSync(inputPath, required) {
|
||||
throw new Error(`Directory '${inputPath}' does not exist`);
|
||||
}
|
||||
exports.directoryExistsSync = directoryExistsSync;
|
||||
/**
|
||||
* Writes the changelog to the given the file
|
||||
*/
|
||||
function writeOutput(githubWorkspacePath, outputFile, changelog) {
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.writeOutput = writeOutput;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Generated
+13095
-1
File diff suppressed because it is too large
Load Diff
+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