Skip to content

Commit 7e44107

Browse files
lykahb9999years
authored andcommitted
Collect and report number of changes
1 parent de90cc6 commit 7e44107

File tree

11 files changed

+376
-169
lines changed

11 files changed

+376
-169
lines changed

Diff for: CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
# v3.0.3
4+
- Added stat feature which computes diffs in subtrees
5+
36
## v3.0.2
47
- [Add config parameter for predicate quantifier](https://github.com/dorny/paths-filter/pull/224)
58

Diff for: README.md

+40-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Paths Changes Filter
1+
# Paths Changes Filter And Diff Stat
22

33
[GitHub Action](https://github.com/features/actions) that enables conditional execution of workflow steps and jobs, based on the files modified by pull request, on a feature
44
branch, or by the recently pushed commits.
@@ -7,6 +7,8 @@ Run slow tasks like integration tests or deployments only for changed components
77
GitHub workflows built-in [path filters](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpaths)
88
don't allow this because they don't work on a level of individual jobs or steps.
99

10+
This is a fork of [dorny/paths-filter](https://github.com/dorny/paths-filter) that adds the feature of diff stat output. The reason behind forking is that original project is dormant.
11+
1012
**Real world usage examples:**
1113

1214
- [sentry.io](https://sentry.io/) - [backend.yml](https://github.com/getsentry/sentry/blob/2ebe01feab863d89aa7564e6d243b6d80c230ddc/.github/workflows/backend.yml#L36)
@@ -73,13 +75,14 @@ For more scenarios see [examples](#examples) section.
7375
## What's New
7476

7577
- New major release `v3` after update to Node 20 [Breaking change]
78+
- Add `stat` parameter that enables output of the file changes statistics per filter.
7679
- Add `ref` input parameter
7780
- Add `list-files: csv` format
7881
- Configure matrix job to run for each folder with changes using `changes` output
7982
- Improved listing of matching files with `list-files: shell` and `list-files: escape` options
8083
- Paths expressions are now evaluated using [picomatch](https://github.com/micromatch/picomatch) library
8184

82-
For more information, see [CHANGELOG](https://github.com/dorny/paths-filter/blob/master/CHANGELOG.md)
85+
For more information, see [CHANGELOG](https://github.com/lykahb/paths-filter/blob/master/CHANGELOG.md)
8386

8487
## Usage
8588

@@ -154,14 +157,14 @@ For more information, see [CHANGELOG](https://github.com/dorny/paths-filter/blob
154157
# Default: ${{ github.token }}
155158
token: ''
156159
157-
# Optional parameter to override the default behavior of file matching algorithm.
160+
# Optional parameter to override the default behavior of file matching algorithm.
158161
# By default files that match at least one pattern defined by the filters will be included.
159162
# This parameter allows to override the "at least one pattern" behavior to make it so that
160-
# all of the patterns have to match or otherwise the file is excluded.
161-
# An example scenario where this is useful if you would like to match all
162-
# .ts files in a sub-directory but not .md files.
163-
# The filters below will match markdown files despite the exclusion syntax UNLESS
164-
# you specify 'every' as the predicate-quantifier parameter. When you do that,
163+
# all of the patterns have to match or otherwise the file is excluded.
164+
# An example scenario where this is useful if you would like to match all
165+
# .ts files in a sub-directory but not .md files.
166+
# The filters below will match markdown files despite the exclusion syntax UNLESS
167+
# you specify 'every' as the predicate-quantifier parameter. When you do that,
165168
# it will only match the .ts files in the subdirectory as expected.
166169
#
167170
# backend:
@@ -179,6 +182,7 @@ For more information, see [CHANGELOG](https://github.com/dorny/paths-filter/blob
179182
- For each filter, it sets an output variable with the name `${FILTER_NAME}_count` to the count of matching files.
180183
- If enabled, for each filter it sets an output variable with the name `${FILTER_NAME}_files`. It will contain a list of all files matching the filter.
181184
- `changes` - JSON array with names of all filters matching any of the changed files.
185+
- If `stat` input is set to an output format, the output variable `stat` contains JSON or CSV value with the change statistics for each filter.
182186

183187
## Examples
184188

@@ -558,10 +562,37 @@ jobs:
558562
559563
</details>
560564
565+
<details>
566+
<summary>Passing number of added lines from a filter to another action</summary>
567+
568+
```yaml
569+
- uses: dorny/paths-filter@v2
570+
id: filter
571+
with:
572+
# Enable listing of diff stat matching each filter.
573+
# Paths to files will be available in `stat` output variable.
574+
# Stat will be formatted as JSON object
575+
stat: json
576+
577+
# In this example all changed files are passed to the following action to do
578+
# some custom processing.
579+
filters: |
580+
changed:
581+
- '**'
582+
- name: Lint Markdown
583+
uses: johndoe/some-action@v1
584+
# Run action only if the change is large enough.
585+
if: ${{fromJson(steps.filter.outputs.stat).changed.additionCount > 1000}}
586+
with:
587+
files: ${{ steps.filter.outputs.changed_files }}
588+
```
589+
590+
</details>
591+
561592
## See also
562593
563594
- [test-reporter](https://github.com/dorny/test-reporter) - Displays test results from popular testing frameworks directly in GitHub
564595
565596
## License
566597
567-
The scripts and documentation in this project are released under the [MIT License](https://github.com/dorny/paths-filter/blob/master/LICENSE)
598+
The scripts and documentation in this project are released under the [MIT License](https://github.com/lykahb/paths-filter/blob/master/LICENSE)

Diff for: __tests__/filter.test.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ describe('matching specific change status', () => {
181181
- added: "**/*"
182182
`
183183
let filter = new Filter(yaml)
184-
const files = [{status: ChangeStatus.Added, filename: 'file.js'}]
184+
const files = [{status: ChangeStatus.Added, filename: 'file.js', additions: 1, deletions: 0}]
185185
const match = filter.match(files)
186186
expect(match.add).toEqual(files)
187187
})
@@ -192,7 +192,7 @@ describe('matching specific change status', () => {
192192
- added|modified: "**/*"
193193
`
194194
let filter = new Filter(yaml)
195-
const files = [{status: ChangeStatus.Modified, filename: 'file.js'}]
195+
const files = [{status: ChangeStatus.Modified, filename: 'file.js', additions: 1, deletions: 1}]
196196
const match = filter.match(files)
197197
expect(match.addOrModify).toEqual(files)
198198
})
@@ -214,12 +214,6 @@ describe('matching specific change status', () => {
214214

215215
function modified(paths: string[]): File[] {
216216
return paths.map(filename => {
217-
return {filename, status: ChangeStatus.Modified}
218-
})
219-
}
220-
221-
function renamed(paths: string[]): File[] {
222-
return paths.map(filename => {
223-
return {filename, status: ChangeStatus.Renamed}
217+
return {filename, status: ChangeStatus.Modified, additions: 1, deletions: 1}
224218
})
225219
}

Diff for: __tests__/git.test.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as git from '../src/git'
22
import {ChangeStatus} from '../src/file'
33

44
describe('parsing output of the git diff command', () => {
5-
test('parseGitDiffOutput returns files with correct change status', async () => {
6-
const files = git.parseGitDiffOutput(
5+
test('parseGitDiffNameStatusOutput returns files with correct change status', async () => {
6+
const files = git.parseGitDiffNameStatusOutput(
77
'A\u0000LICENSE\u0000' + 'M\u0000src/index.ts\u0000' + 'D\u0000src/main.ts\u0000'
88
)
99
expect(files.length).toBe(3)
@@ -14,6 +14,17 @@ describe('parsing output of the git diff command', () => {
1414
expect(files[2].filename).toBe('src/main.ts')
1515
expect(files[2].status).toBe(ChangeStatus.Deleted)
1616
})
17+
18+
test('parseGitDiffNumstatOutput returns files with correct change status', async () => {
19+
const files = git.parseGitDiffNumstatOutput('4\t2\tLICENSE\u0000' + '5\t0\tsrc/index.ts\u0000')
20+
expect(files.length).toBe(2)
21+
expect(files[0].filename).toBe('LICENSE')
22+
expect(files[0].additions).toBe(4)
23+
expect(files[0].deletions).toBe(2)
24+
expect(files[1].filename).toBe('src/index.ts')
25+
expect(files[1].additions).toBe(5)
26+
expect(files[1].deletions).toBe(0)
27+
})
1728
})
1829

1930
describe('git utility function tests (those not invoking git)', () => {

Diff for: action.yml

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name: 'Paths Changes Filter'
1+
name: 'Paths Changes Filter And Diff Stat'
22
description: 'Execute your workflow steps only if relevant files are modified.'
3-
author: 'Michal Dorner <[email protected]>'
3+
author: 'Michal Dorner <[email protected]>, Boris Lykah<[email protected]>'
44
inputs:
55
token:
66
description: 'GitHub Access Token'
@@ -36,6 +36,16 @@ inputs:
3636
Backslash escapes every potentially unsafe character.
3737
required: false
3838
default: none
39+
stat:
40+
description: |
41+
Enables listing of that enables output of the file change statistics per filter, similar to `git diff --shortstat`.
42+
If some changes do not match any filter, the output includes an additional entry with the filter name 'other'.
43+
'none' - Disables listing of stats (default).
44+
'csv' - Coma separated list that has name of filter, count of additions, count of deletions, count of changed files.
45+
If needed it uses double quotes to wrap name of filter with unsafe characters. For example, `"some filter",12,7,2`.
46+
'json' - Serialized as JSON object where the filter names are keys. For example, `{"some filter": {"additionCount": 12, "deletionCount": 7, "fileCount": 2}}`
47+
required: false
48+
default: none
3949
initial-fetch-depth:
4050
description: |
4151
How many commits are initially fetched from base branch.

0 commit comments

Comments
 (0)