Skip to content

Commit 3429301

Browse files
authored
Merge pull request #1458 from mikepenz/copilot/fix-1457
Add path filtering support for monorepo setups
2 parents 47f1220 + 4a8e4e9 commit 3429301

File tree

14 files changed

+311
-169
lines changed

14 files changed

+311
-169
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,28 @@ Depending on the use-case additional settings can be provided to the action
204204
token: ${{ secrets.PAT }}
205205
```
206206
207+
<details><summary><b>Monorepo Configuration</b></summary>
208+
<p>
209+
210+
For **monorepo setups**, you can filter commits by path to generate changelogs only for specific components:
211+
212+
```yml
213+
- name: "App1 Changelog"
214+
id: build_app1_changelog
215+
if: startsWith(github.ref, 'refs/tags/')
216+
uses: mikepenz/release-changelog-builder-action@{latest-release}
217+
with:
218+
includeOnlyPaths: |
219+
app1/
220+
shared/
221+
fromTag: "v1.0.0"
222+
toTag: "v2.0.0"
223+
token: ${{ secrets.GITHUB_TOKEN }}
224+
```
225+
226+
</p>
227+
</details>
228+
207229
> [!NOTE]
208230
> All input values are optional. It is only required to provide the `token` either via the input, or as `env` variable.
209231

@@ -231,6 +253,7 @@ Depending on the use-case additional settings can be provided to the action
231253
| `exportCache` | Will enable exporting the fetched PR information to a cache, which can be re-used by later runs. Default: false |
232254
| `exportOnly` | When enabled, will result in only exporting the cache, without generating a changelog. Default: false (Requires `exportCache` to be enabled) |
233255
| `cache` | The file path to write/read the cache to/from. |
256+
| `includeOnlyPaths` | List of path patterns to include. Provide as multiline input (one per line). Only commits that touched these paths will be included in the changelog. Useful for monorepo setups where you want to filter commits by their affected paths. GitHub (non-offline mode): when `includeOnlyPaths` is defined, the action performs an extra API call per commit to determine which files were modified by that commit. This can significantly increase API usage for large diffs. |
234257

235258
> [!WARNING]
236259
> `${{ secrets.GITHUB_TOKEN }}` only grants rights to the current repository, for other repositories please use a PAT (Personal Access Token).

__tests__/pathFiltering.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import {CommitInfo, filterCommits} from '../src/pr-collector/commits.js'
2+
import moment from 'moment'
3+
import {expect, describe, test} from 'vitest'
4+
5+
describe('Path Filtering', () => {
6+
test('should filter commits by merge branches (existing functionality)', () => {
7+
const commits: CommitInfo[] = [
8+
{
9+
sha: 'commit1',
10+
summary: 'feat: add new feature',
11+
message: 'feat: add new feature\n\nDetailed description',
12+
author: 'user1',
13+
authorName: 'User One',
14+
authorDate: moment(),
15+
committer: 'user1',
16+
committerName: 'User One',
17+
commitDate: moment()
18+
},
19+
{
20+
sha: 'commit2',
21+
summary: 'Merge pull request #123 from feature-branch',
22+
message: 'Merge pull request #123 from feature-branch',
23+
author: 'user2',
24+
authorName: 'User Two',
25+
authorDate: moment(),
26+
committer: 'user2',
27+
committerName: 'User Two',
28+
commitDate: moment()
29+
},
30+
{
31+
sha: 'commit3',
32+
summary: 'fix: bug fix',
33+
message: 'fix: bug fix',
34+
author: 'user3',
35+
authorName: 'User Three',
36+
authorDate: moment(),
37+
committer: 'user3',
38+
committerName: 'User Three',
39+
commitDate: moment()
40+
}
41+
]
42+
43+
const excludeMergeBranches = ['Merge pull request']
44+
const filtered = filterCommits(commits, excludeMergeBranches)
45+
46+
expect(filtered).toHaveLength(2)
47+
expect(filtered[0].sha).toBe('commit1')
48+
expect(filtered[1].sha).toBe('commit3')
49+
})
50+
})

action.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ inputs:
6666
platform:
6767
description: 'Defines the platform the action is run on. Available options: [`github`, `gitea`]. Defaults to `github`.'
6868
default: "github"
69+
includeOnlyPaths:
70+
description: 'List of path patterns to include. Provide as multiline input (one per line). Only commits that touched these paths will be included in the changelog. Useful for monorepo setups.'
6971
outputs:
7072
changelog:
7173
description: The built release changelog built from the merged pull requests

0 commit comments

Comments
 (0)