Skip to content

Commit

Permalink
feat: Add git-path option
Browse files Browse the repository at this point in the history
`git-path` acts as a 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).

closes #178
  • Loading branch information
AlmogBaku committed Sep 19, 2022
1 parent 78239f1 commit 96b4f2c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -11,14 +11,16 @@ This action will bump version, tag commit and generate a changelog with conventi
- **Optional** `git-pull-method`: The git pull method used when pulling all changes from remote. Default `--ff-only`
- **Optional** `git-push`: Push all the GIT changes. Default `true`
- **Optional** `git-branch`: The branch used to push. Default is the current branch (`${{ github.ref }}`)
- **Optional** `git-url`: Git repository domain. Default is `github.com`
- **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** `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** `version-file`: The path to the file that contains the version to bump. 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'`.
- **Optional** `skip-on-empty`: Boolean to specify if you want to skip empty release (no-changelog generated). This case occured when you push `chore` commit with `angular` for example. Default `'true'`.
- **Optional** `skip-on-empty`: Boolean to specify if you want to skip empty release (no-changelog generated). This case occurred when you push `chore` commit with `angular` for example. Default `'true'`.
- **Optional** `skip-version-file`: Do not update the version file. Default `'false'`.
- **Optional** `skip-commit`: Do not create a release commit. Default `'false'`.
- **Optional** `pre-commit`: Path to the pre-commit script file. No hook by default.
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Expand Up @@ -118,6 +118,11 @@ inputs:
default: 'github.com'
required: false

git-path:
description: 'Path filter for the logs. If set, only commits that match the path filter will be considered'
default: ''
required: false

skip-ci:
description: 'Adds [skip ci] to commit message, to avoid triggering a new build'
default: 'true'
Expand Down
20 changes: 14 additions & 6 deletions src/helpers/generateChangelog.js
Expand Up @@ -8,9 +8,11 @@ const conventionalChangelog = require('conventional-changelog')
* @param preset
* @param version
* @param releaseCount
* @param config
* @param gitPath
* @returns {*}
*/
const getChangelogStream = (tagPrefix, preset, version, releaseCount, config) => conventionalChangelog({
const getChangelogStream = (tagPrefix, preset, version, releaseCount, config, gitPath) => conventionalChangelog({
preset,
releaseCount: parseInt(releaseCount, 10),
tagPrefix,
Expand All @@ -20,7 +22,9 @@ const getChangelogStream = (tagPrefix, preset, version, releaseCount, config) =>
version,
currentTag: `${tagPrefix}${version}`,
},
{},
{
path: gitPath === '' || gitPath === null ? undefined : gitPath
},
config && config.parserOpts,
config && config.writerOpts
)
Expand All @@ -34,10 +38,12 @@ module.exports = getChangelogStream
* @param preset
* @param version
* @param releaseCount
* @param config
* @param gitPath
* @returns {Promise<string>}
*/
module.exports.generateStringChangelog = (tagPrefix, preset, version, releaseCount, config) => new Promise((resolve, reject) => {
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config)
module.exports.generateStringChangelog = (tagPrefix, preset, version, releaseCount, config, gitPath) => new Promise((resolve, reject) => {
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config, gitPath)

let changelog = ''

Expand All @@ -56,10 +62,12 @@ module.exports.generateStringChangelog = (tagPrefix, preset, version, releaseCou
* @param version
* @param fileName
* @param releaseCount
* @param config
* @param gitPath
* @returns {Promise<>}
*/
module.exports.generateFileChangelog = (tagPrefix, preset, version, fileName, releaseCount, config) => new Promise((resolve) => {
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config)
module.exports.generateFileChangelog = (tagPrefix, preset, version, fileName, releaseCount, config, gitPath) => new Promise((resolve) => {
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config, gitPath)

changelogStream
.pipe(fs.createWriteStream(fileName))
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Expand Up @@ -44,6 +44,7 @@ async function run() {
const conventionalConfigFile = core.getInput('config-file-path')
const preChangelogGenerationFile = core.getInput('pre-changelog-generation')
const gitUrl = core.getInput('git-url')
const gitPath = core.getInput('git-path')
const skipCi = core.getBooleanInput('skip-ci')
const createSummary = core.getBooleanInput('create-summary')

Expand All @@ -63,6 +64,7 @@ async function run() {
core.info(`Using "${conventionalConfigFile}" as config file`)
core.info(`Using "${gitUrl}" as gitUrl`)
core.info(`Using "${gitBranch}" as gitBranch`)
core.info(`Using "${gitPath}" as gitPath`)

if (preCommitFile) {
core.info(`Using "${preCommitFile}" as pre-commit script`)
Expand Down Expand Up @@ -144,7 +146,7 @@ async function run() {
}

// Generate the string changelog
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, newVersion, 1, config)
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, newVersion, 1, config, gitPath)
core.info('Changelog generated')
core.info(stringChangelog)

Expand All @@ -162,7 +164,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)
await changelog.generateFileChangelog(tagPrefix, preset, newVersion, outputFile, releaseCount, config, gitPath)
}

if (!skipCommit) {
Expand Down

0 comments on commit 96b4f2c

Please sign in to comment.