feat: Add 'infile' option
parent
84d56d6ef8
commit
a858fade68
|
@ -15,8 +15,9 @@ This action will bump version, tag commit and generate a changelog with conventi
|
|||
- **Optional** `git-path`: Path filter for the logs. If set, only commits that match the path filter will be considered. By default, we won't use this feature(empty string).
|
||||
- **Optional** `preset`: Preset that is used from conventional commits. Default `angular`.
|
||||
- **Optional** `tag-prefix`: Prefix for the git tags. Default `v`.
|
||||
- **Optional** `input-file`: Read the changelog from this file. This will prepend the newly generated changelogs to the file's content.
|
||||
- **Optional** `output-file`: File to output the changelog to. Default `CHANGELOG.md`, when providing `'false'` no file will be generated / updated.
|
||||
- **Optional** `release-count`: Number of releases to preserve in changelog. Default `5`, use `0` to regenerate all.
|
||||
- **Optional** `release-count`: Number of releases to preserve in changelog. Default `5`, use `0` to regenerate all. This input has no effect if `input-file` is used.
|
||||
- **Optional** `version-file`: The path to the file that contains the version to bump (supports comma-separated list of file paths). Default `./package.json`.
|
||||
- **Optional** `version-path`: The place inside the version file to bump. Default `version`.
|
||||
- **Optional** `skip-git-pull`: Do not pull the repo before tagging. Ensure you full cloned the repo in the first place to get tags. Default `'false'`.
|
||||
|
|
|
@ -56,13 +56,17 @@ inputs:
|
|||
default: "v"
|
||||
required: false
|
||||
|
||||
input-file:
|
||||
description: "Read the changelog from this file. This will prepend the newly generated changelogs to the file's content"
|
||||
required: false
|
||||
|
||||
output-file:
|
||||
description: "File to output the changelog to"
|
||||
default: "CHANGELOG.md"
|
||||
required: false
|
||||
|
||||
release-count:
|
||||
description: "Number of releases to preserve in changelog"
|
||||
description: "Number of releases to preserve in changelog. Default `5`, use `0` to regenerate all. This input has no effect if input-file is used"
|
||||
default: "5"
|
||||
required: false
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const fs = require('fs')
|
||||
const { Readable } = require('stream');
|
||||
const conventionalChangelog = require('conventional-changelog')
|
||||
|
||||
/**
|
||||
|
@ -67,12 +68,45 @@ module.exports.generateStringChangelog = (tagPrefix, preset, version, releaseCou
|
|||
* @param releaseCount
|
||||
* @param config
|
||||
* @param gitPath
|
||||
* @param infile
|
||||
* @returns {Promise<>}
|
||||
*/
|
||||
module.exports.generateFileChangelog = (tagPrefix, preset, version, fileName, releaseCount, config, gitPath) => new Promise((resolve) => {
|
||||
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config, gitPath)
|
||||
module.exports.generateFileChangelog = (tagPrefix, preset, version, fileName, releaseCount, config, gitPath, infile) => new Promise((resolve) => {
|
||||
const changelogStream = getChangelogStream(tagPrefix, preset, version, infile ? 1 : releaseCount, config, gitPath)
|
||||
|
||||
// The default changelog output to be streamed first
|
||||
const readStreams = [changelogStream]
|
||||
|
||||
// If an input-file is provided and release count is not 0
|
||||
if (infile) {
|
||||
// The infile is read synchronously to avoid repeatedly reading newly written content while it is being written
|
||||
const buffer = fs.readFileSync(infile);
|
||||
const readableStream = Readable.from(buffer);
|
||||
// We add the stream as the next item for later pipe
|
||||
readStreams.push(readableStream)
|
||||
}
|
||||
|
||||
const writeStream = fs.createWriteStream(fileName)
|
||||
|
||||
let currentIndex = 0;
|
||||
|
||||
function pipeNextStream() {
|
||||
if (currentIndex < readStreams.length) {
|
||||
const currentStream = readStreams[currentIndex];
|
||||
|
||||
currentStream.pipe(writeStream, { end: false });
|
||||
|
||||
currentStream.once('end', () => {
|
||||
currentIndex++;
|
||||
pipeNextStream();
|
||||
});
|
||||
} else {
|
||||
// All stream pipes have completed
|
||||
writeStream.end();
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
|
||||
pipeNextStream();
|
||||
|
||||
changelogStream
|
||||
.pipe(fs.createWriteStream(fileName))
|
||||
.on('finish', resolve)
|
||||
})
|
||||
|
|
|
@ -46,6 +46,7 @@ async function run() {
|
|||
const preChangelogGenerationFile = core.getInput('pre-changelog-generation')
|
||||
const gitUrl = core.getInput('git-url')
|
||||
const gitPath = core.getInput('git-path')
|
||||
const infile = core.getInput('input-file')
|
||||
const skipCi = core.getBooleanInput('skip-ci')
|
||||
const createSummary = core.getBooleanInput('create-summary')
|
||||
const prerelease = core.getBooleanInput('pre-release')
|
||||
|
@ -72,6 +73,10 @@ async function run() {
|
|||
core.info(`Using "${preCommitFile}" as pre-commit script`)
|
||||
}
|
||||
|
||||
if (infile) {
|
||||
core.info(`Using "${infile}" as input file`)
|
||||
}
|
||||
|
||||
if (preChangelogGenerationFile) {
|
||||
core.info(`Using "${preChangelogGenerationFile}" as pre-changelog-generation script`)
|
||||
}
|
||||
|
@ -172,7 +177,7 @@ async function run() {
|
|||
// If output file === 'false' we don't write it to file
|
||||
if (outputFile !== 'false') {
|
||||
// Generate the changelog
|
||||
await changelog.generateFileChangelog(tagPrefix, preset, newVersion, outputFile, releaseCount, config, gitPath)
|
||||
await changelog.generateFileChangelog(tagPrefix, preset, newVersion, outputFile, releaseCount, config, gitPath, infile)
|
||||
}
|
||||
|
||||
if (!skipCommit) {
|
||||
|
|
Loading…
Reference in New Issue