Skip to content

Commit

Permalink
Merge pull request #3 from lykahb/numstat
Browse files Browse the repository at this point in the history
Output the stat data
  • Loading branch information
lykahb committed Mar 11, 2022
2 parents 1ec7035 + e835d01 commit ac863d4
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 148 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ For more scenarios see [examples](#examples) section.

## What's New

- Add `stat` parameter that enables output of the file changes statistics per filter.
- Add `ref` input parameter
- Add `list-files: csv` format
- Configure matrix job to run for each folder with changes using `changes` output
Expand Down Expand Up @@ -160,6 +161,7 @@ For more information, see [CHANGELOG](https://github.com/dorny/paths-filter/blob
- For each filter, it sets an output variable with the name `${FILTER_NAME}_count` to the count of matching files.
- 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.
- `changes` - JSON array with names of all filters matching any of the changed files.
- 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.

## Examples

Expand Down Expand Up @@ -504,6 +506,33 @@ jobs:
</details>
<details>
<summary>Passing number of added lines from a filter to another action</summary>
```yaml
- uses: dorny/paths-filter@v2
id: filter
with:
# Enable listing of diff stat matching each filter.
# Paths to files will be available in `stat` output variable.
# Stat will be formatted as JSON object
stat: json

# In this example all changed files are passed to the following action to do
# some custom processing.
filters: |
changed:
- '**'
- name: Lint Markdown
uses: johndoe/some-action@v1
# Run action only if the change is large enough.
if: ${{fromJson(steps.filter.outputs.stat).changed.additionCount > 1000}}
with:
files: ${{ steps.filter.outputs.changed_files }}
```
</details>
## See also
- [test-reporter](https://github.com/dorny/test-reporter) - Displays test results from popular testing frameworks directly in GitHub
Expand Down
6 changes: 3 additions & 3 deletions __tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('matching specific change status', () => {
- added: "**/*"
`
let filter = new Filter(yaml)
const files = [{status: ChangeStatus.Added, filename: 'file.js'}]
const files = [{status: ChangeStatus.Added, filename: 'file.js', additions: 1, deletions: 0}]
const match = filter.match(files)
expect(match.add).toEqual(files)
})
Expand All @@ -161,7 +161,7 @@ describe('matching specific change status', () => {
- added|modified: "**/*"
`
let filter = new Filter(yaml)
const files = [{status: ChangeStatus.Modified, filename: 'file.js'}]
const files = [{status: ChangeStatus.Modified, filename: 'file.js', additions: 1, deletions: 1}]
const match = filter.match(files)
expect(match.addOrModify).toEqual(files)
})
Expand All @@ -183,6 +183,6 @@ describe('matching specific change status', () => {

function modified(paths: string[]): File[] {
return paths.map(filename => {
return {filename, status: ChangeStatus.Modified}
return {filename, status: ChangeStatus.Modified, additions: 1, deletions: 1}
})
}
17 changes: 15 additions & 2 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import * as git from '../src/git'
import {ChangeStatus} from '../src/file'

describe('parsing output of the git diff command', () => {
test('parseGitDiffOutput returns files with correct change status', async () => {
const files = git.parseGitDiffOutput(
test('parseGitDiffNameStatusOutput returns files with correct change status', async () => {
const files = git.parseGitDiffNameStatusOutput(
'A\u0000LICENSE\u0000' + 'M\u0000src/index.ts\u0000' + 'D\u0000src/main.ts\u0000'
)
expect(files.length).toBe(3)
Expand All @@ -14,6 +14,19 @@ describe('parsing output of the git diff command', () => {
expect(files[2].filename).toBe('src/main.ts')
expect(files[2].status).toBe(ChangeStatus.Deleted)
})

test('parseGitDiffNumstatOutput returns files with correct change status', async () => {
const files = git.parseGitDiffNumstatOutput(
'4\t2\tLICENSE\u0000' + '5\t0\tsrc/index.ts\u0000'
)
expect(files.length).toBe(2)
expect(files[0].filename).toBe('LICENSE')
expect(files[0].additions).toBe(4)
expect(files[0].deletions).toBe(2)
expect(files[1].filename).toBe('src/index.ts')
expect(files[1].additions).toBe(5)
expect(files[1].deletions).toBe(0)
})
})

describe('git utility function tests (those not invoking git)', () => {
Expand Down
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ inputs:
Backslash escapes every potentially unsafe character.
required: true
default: none
stat:
description: |
Enables listing of that enables output of the file change statistics per filter, similar to `git diff --shortstat`.
If some changes do not match any filter, the output includes an additional entry with the filter name 'other'.
'none' - Disables listing of stats (default).
'csv' - Coma separated list that has name of filter, count of additions, count of deletions, count of changed files.
If needed it uses double quotes to wrap name of filter with unsafe characters. For example, `"some filter",12,7,2`.
'json' - Serialized as JSON object where the filter names are keys. For example, `{"some filter": {"additionCount": 12, "deletionCount": 7, "fileCount": 2}}`
required: false
default: none
initial-fetch-depth:
description: |
How many commits are initially fetched from base branch.
Expand Down
Loading

0 comments on commit ac863d4

Please sign in to comment.