Skip to content

Commit 1988ff6

Browse files
Merge pull request #95 from step-security/shubham-patch-1
chore: fast forward upstream changes v2.11.1->v3.0.2
2 parents 230afa2 + 92775c7 commit 1988ff6

File tree

8 files changed

+36290
-42307
lines changed

8 files changed

+36290
-42307
lines changed

README.md

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ don't allow this because they don't work on a level of individual jobs or steps.
4848
## Example
4949

5050
```yaml
51-
- uses: step-security/paths-filter@v2
51+
- uses: step-security/paths-filter@v3
5252
id: changes
5353
with:
5454
filters: |
@@ -72,10 +72,19 @@ For more scenarios see [examples](#examples) section.
7272
- Local execution with [act](https://github.com/nektos/act) works only with alternative runner image. Default runner doesn't have `git` binary.
7373
- Use: `act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04`
7474

75+
## What's New
76+
77+
- New major release `v3` after update to Node 20 [Breaking change]
78+
- Add `ref` input parameter
79+
- Add `list-files: csv` format
80+
- Configure matrix job to run for each folder with changes using `changes` output
81+
- Improved listing of matching files with `list-files: shell` and `list-files: escape` options
82+
- Paths expressions are now evaluated using [picomatch](https://github.com/micromatch/picomatch) library
83+
7584
## Usage
7685

7786
```yaml
78-
- uses: step-security/paths-filter@v2
87+
- uses: step-security/paths-filter@v3
7988
with:
8089
# Defines filters applied to detected changed files.
8190
# Each filter has a name and a list of rules.
@@ -144,6 +153,22 @@ For more scenarios see [examples](#examples) section.
144153
# changes using git commands.
145154
# Default: ${{ github.token }}
146155
token: ''
156+
157+
# Optional parameter to override the default behavior of file matching algorithm.
158+
# By default files that match at least one pattern defined by the filters will be included.
159+
# 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,
165+
# it will only match the .ts files in the subdirectory as expected.
166+
#
167+
# backend:
168+
# - 'pkg/a/b/c/**'
169+
# - '!**/*.jpeg'
170+
# - '!**/*.md'
171+
predicate-quantifier: 'some'
147172
```
148173

149174
## Outputs
@@ -167,8 +192,8 @@ jobs:
167192
tests:
168193
runs-on: ubuntu-latest
169194
steps:
170-
- uses: actions/checkout@v3
171-
- uses: step-security/paths-filter@v2
195+
- uses: actions/checkout@v4
196+
- uses: step-security/paths-filter@v3
172197
id: filter
173198
with:
174199
filters: |
@@ -212,7 +237,7 @@ jobs:
212237
frontend: ${{ steps.filter.outputs.frontend }}
213238
steps:
214239
# For pull requests it's not necessary to checkout the code
215-
- uses: step-security/paths-filter@v2
240+
- uses: step-security/paths-filter@v3
216241
id: filter
217242
with:
218243
filters: |
@@ -227,7 +252,7 @@ jobs:
227252
if: ${{ needs.changes.outputs.backend == 'true' }}
228253
runs-on: ubuntu-latest
229254
steps:
230-
- uses: actions/checkout@v3
255+
- uses: actions/checkout@v4
231256
- ...
232257
233258
# JOB to build and test frontend code
@@ -236,7 +261,7 @@ jobs:
236261
if: ${{ needs.changes.outputs.frontend == 'true' }}
237262
runs-on: ubuntu-latest
238263
steps:
239-
- uses: actions/checkout@v3
264+
- uses: actions/checkout@v4
240265
- ...
241266
```
242267

@@ -258,7 +283,7 @@ jobs:
258283
packages: ${{ steps.filter.outputs.changes }}
259284
steps:
260285
# For pull requests it's not necessary to checkout the code
261-
- uses: step-security/paths-filter@v2
286+
- uses: step-security/paths-filter@v3
262287
id: filter
263288
with:
264289
filters: |
@@ -275,7 +300,7 @@ jobs:
275300
package: ${{ fromJSON(needs.changes.outputs.packages) }}
276301
runs-on: ubuntu-latest
277302
steps:
278-
- uses: actions/checkout@v3
303+
- uses: actions/checkout@v4
279304
- ...
280305
```
281306

@@ -299,8 +324,8 @@ jobs:
299324
permissions:
300325
pull-requests: read
301326
steps:
302-
- uses: actions/checkout@v3
303-
- uses: step-security/paths-filter@v2
327+
- uses: actions/checkout@v4
328+
- uses: step-security/paths-filter@v3
304329
id: filter
305330
with:
306331
filters: ... # Configure your filters
@@ -320,12 +345,12 @@ jobs:
320345
build:
321346
runs-on: ubuntu-latest
322347
steps:
323-
- uses: actions/checkout@v3
348+
- uses: actions/checkout@v4
324349
with:
325350
# This may save additional git fetch roundtrip if
326351
# merge-base is found within latest 20 commits
327352
fetch-depth: 20
328-
- uses: step-security/paths-filter@v2
353+
- uses: step-security/paths-filter@v3
329354
id: filter
330355
with:
331356
base: develop # Change detection against merge-base with this branch
@@ -348,8 +373,8 @@ jobs:
348373
build:
349374
runs-on: ubuntu-latest
350375
steps:
351-
- uses: actions/checkout@v3
352-
- uses: step-security/paths-filter@v2
376+
- uses: actions/checkout@v4
377+
- uses: step-security/paths-filter@v3
353378
id: filter
354379
with:
355380
# Use context to get the branch where commits were pushed.
@@ -376,14 +401,14 @@ jobs:
376401
build:
377402
runs-on: ubuntu-latest
378403
steps:
379-
- uses: actions/checkout@v3
404+
- uses: actions/checkout@v4
380405
381406
# Some action that modifies files tracked by git (e.g. code linter)
382407
- uses: johndoe/some-action@v1
383408
384409
# Filter to detect which files were modified
385410
# Changes could be, for example, automatically committed
386-
- uses: step-security/paths-filter@v2
411+
- uses: step-security/paths-filter@v3
387412
id: filter
388413
with:
389414
base: HEAD
@@ -398,7 +423,7 @@ jobs:
398423
<summary>Define filter rules in own file</summary>
399424

400425
```yaml
401-
- uses: step-security/paths-filter@v2
426+
- uses: step-security/paths-filter@v3
402427
id: filter
403428
with:
404429
# Path to file where filters are defined
@@ -411,7 +436,7 @@ jobs:
411436
<summary>Use YAML anchors to reuse path expression(s) inside another rule</summary>
412437

413438
```yaml
414-
- uses: step-security/paths-filter@v2
439+
- uses: step-security/paths-filter@v3
415440
id: filter
416441
with:
417442
# &shared is YAML anchor,
@@ -432,7 +457,7 @@ jobs:
432457
<summary>Consider if file was added, modified or deleted</summary>
433458

434459
```yaml
435-
- uses: step-security/paths-filter@v2
460+
- uses: step-security/paths-filter@v3
436461
id: filter
437462
with:
438463
# Changed file can be 'added', 'modified', or 'deleted'.
@@ -454,13 +479,39 @@ jobs:
454479
455480
</details>
456481
482+
<details>
483+
<summary>Detect changes in folder only for some file extensions</summary>
484+
485+
```yaml
486+
- uses: step-security/paths-filter@v3
487+
id: filter
488+
with:
489+
# This makes it so that all the patterns have to match a file for it to be
490+
# considered changed. Because we have the exclusions for .jpeg and .md files
491+
# the end result is that if those files are changed they will be ignored
492+
# because they don't match the respective rules excluding them.
493+
#
494+
# This can be leveraged to ensure that you only build & test software changes
495+
# that have real impact on the behavior of the code, e.g. you can set up your
496+
# build to run when Typescript/Rust/etc. files are changed but markdown
497+
# changes in the diff will be ignored and you consume less resources to build.
498+
predicate-quantifier: 'every'
499+
filters: |
500+
backend:
501+
- 'pkg/a/b/c/**'
502+
- '!**/*.jpeg'
503+
- '!**/*.md'
504+
```
505+
506+
</details>
507+
457508
### Custom processing of changed files
458509
459510
<details>
460511
<summary>Passing list of modified files as command line args in Linux shell</summary>
461512
462513
```yaml
463-
- uses: step-security/paths-filter@v2
514+
- uses: step-security/paths-filter@v3
464515
id: filter
465516
with:
466517
# Enable listing of files matching each filter.
@@ -486,7 +537,7 @@ jobs:
486537
<summary>Passing list of modified files as JSON array to another action</summary>
487538
488539
```yaml
489-
- uses: step-security/paths-filter@v2
540+
- uses: step-security/paths-filter@v3
490541
id: filter
491542
with:
492543
# Enable listing of files matching each filter.

__tests__/filter.test.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Filter} from '../src/filter'
1+
import {Filter, FilterConfig, PredicateQuantifier} from '../src/filter'
22
import {File, ChangeStatus} from '../src/file'
33

44
describe('yaml filter parsing tests', () => {
@@ -117,6 +117,37 @@ describe('matching tests', () => {
117117
expect(pyMatch.backend).toEqual(pyFiles)
118118
})
119119

120+
test('matches only files that are matching EVERY pattern when set to PredicateQuantifier.EVERY', () => {
121+
const yaml = `
122+
backend:
123+
- 'pkg/a/b/c/**'
124+
- '!**/*.jpeg'
125+
- '!**/*.md'
126+
`
127+
const filterConfig: FilterConfig = {predicateQuantifier: PredicateQuantifier.EVERY}
128+
const filter = new Filter(yaml, filterConfig)
129+
130+
const typescriptFiles = modified(['pkg/a/b/c/some-class.ts', 'pkg/a/b/c/src/main/some-class.ts'])
131+
const otherPkgTypescriptFiles = modified(['pkg/x/y/z/some-class.ts', 'pkg/x/y/z/src/main/some-class.ts'])
132+
const otherPkgJpegFiles = modified(['pkg/x/y/z/some-pic.jpeg', 'pkg/x/y/z/src/main/jpeg/some-pic.jpeg'])
133+
const docsFiles = modified([
134+
'pkg/a/b/c/some-pics.jpeg',
135+
'pkg/a/b/c/src/main/jpeg/some-pic.jpeg',
136+
'pkg/a/b/c/src/main/some-docs.md',
137+
'pkg/a/b/c/some-docs.md'
138+
])
139+
140+
const typescriptMatch = filter.match(typescriptFiles)
141+
const otherPkgTypescriptMatch = filter.match(otherPkgTypescriptFiles)
142+
const docsMatch = filter.match(docsFiles)
143+
const otherPkgJpegMatch = filter.match(otherPkgJpegFiles)
144+
145+
expect(typescriptMatch.backend).toEqual(typescriptFiles)
146+
expect(otherPkgTypescriptMatch.backend).toEqual([])
147+
expect(docsMatch.backend).toEqual([])
148+
expect(otherPkgJpegMatch.backend).toEqual([])
149+
})
150+
120151
test('matches path based on rules included using YAML anchor', () => {
121152
const yaml = `
122153
shared: &shared
@@ -186,3 +217,9 @@ function modified(paths: string[]): File[] {
186217
return {filename, status: ChangeStatus.Modified}
187218
})
188219
}
220+
221+
function renamed(paths: string[]): File[] {
222+
return paths.map(filename => {
223+
return {filename, status: ChangeStatus.Renamed}
224+
})
225+
}

action.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: 'Paths Changes Filter'
22
description: 'Execute your workflow steps only if relevant files are modified.'
3-
author: 'Michal Dorner <[email protected]>'
43
inputs:
54
token:
65
description: 'GitHub Access Token'

0 commit comments

Comments
 (0)