Skip to content

Commit f3d3fc8

Browse files
authored
Merge pull request #85 from dorny/improve-robustness
Improve robustness of change detection
2 parents 87375a4 + aae9c56 commit f3d3fc8

File tree

5 files changed

+233
-157
lines changed

5 files changed

+233
-157
lines changed

Diff for: README.md

+52-54
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Paths Changes Filter
22

3-
This [Github Action](https://github.com/features/actions) enables conditional execution of workflow steps and jobs,
4-
based on the files modified by pull request, feature branch or in pushed commits.
3+
[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
4+
branch, or by the recently pushed commits.
55

6-
It saves time and resources especially in monorepo setups, where you can run slow tasks (e.g. integration tests or deployments) only for changed components.
6+
Run slow tasks like integration tests or deployments only for changed components. It saves time and resources, especially in monorepo setups.
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

@@ -17,27 +17,27 @@ don't allow this because they don't work on a level of individual jobs or steps.
1717
- Workflow triggered by **[pull_request](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request)**
1818
or **[pull_request_target](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target)** event
1919
- Changes are detected against the pull request base branch
20-
- Uses Github REST API to fetch list of modified files
20+
- Uses Github REST API to fetch a list of modified files
2121
- **Feature branches:**
2222
- Workflow triggered by **[push](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push)**
2323
or any other **[event](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows)**
2424
- The `base` input parameter must not be the same as the branch that triggered the workflow
25-
- Changes are detected against the merge-base with configured base branch or default branch
25+
- Changes are detected against the merge-base with the configured base branch or the default branch
2626
- Uses git commands to detect changes - repository must be already [checked out](https://github.com/actions/checkout)
27-
- **Master, Release or other long-lived branches:**
27+
- **Master, Release, or other long-lived branches:**
2828
- Workflow triggered by **[push](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#push)** event
29-
when `base` input parameter is same as the branch that triggered the workflow:
29+
when `base` input parameter is the same as the branch that triggered the workflow:
3030
- Changes are detected against the most recent commit on the same branch before the push
3131
- Workflow triggered by any other **[event](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows)**
3232
when `base` input parameter is commit SHA:
3333
- Changes are detected against the provided `base` commit
3434
- Workflow triggered by any other **[event](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows)**
35-
when `base` input parameter is same as the branch that triggered the workflow:
36-
- Changes are detected from last commit
35+
when `base` input parameter is the same as the branch that triggered the workflow:
36+
- Changes are detected from the last commit
3737
- Uses git commands to detect changes - repository must be already [checked out](https://github.com/actions/checkout)
3838
- **Local changes**
3939
- Workflow triggered by any event when `base` input parameter is set to `HEAD`
40-
- Changes are detected against current HEAD
40+
- Changes are detected against the current HEAD
4141
- Untracked files are ignored
4242

4343
## Example
@@ -57,10 +57,10 @@ For more scenarios see [examples](#examples) section.
5757
5858
## Notes:
5959
- Paths expressions are evaluated using [picomatch](https://github.com/micromatch/picomatch) library.
60-
Documentation for path expression format can be found on project github page.
60+
Documentation for path expression format can be found on the project GitHub page.
6161
- Picomatch [dot](https://github.com/micromatch/picomatch#options) option is set to true.
62-
Globbing will match also paths where file or folder name starts with a dot.
63-
- It's recommended to quote your path expressions with `'` or `"`. Otherwise you will get an error if it starts with `*`.
62+
Globbing will also match paths where file or folder name starts with a dot.
63+
- It's recommended to quote your path expressions with `'` or `"`. Otherwise, you will get an error if it starts with `*`.
6464
- Local execution with [act](https://github.com/nektos/act) works only with alternative runner image. Default runner doesn't have `git` binary.
6565
- Use: `act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04`
6666

@@ -72,54 +72,52 @@ For more scenarios see [examples](#examples) section.
7272
- Improved listing of matching files with `list-files: shell` and `list-files: escape` options
7373
- Paths expressions are now evaluated using [picomatch](https://github.com/micromatch/picomatch) library
7474

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

7777
# Usage
7878

7979
```yaml
8080
- uses: dorny/paths-filter@v2
8181
with:
8282
# Defines filters applied to detected changed files.
83-
# Each filter has a name and list of rules.
83+
# Each filter has a name and a list of rules.
8484
# Rule is a glob expression - paths of all changed
8585
# files are matched against it.
8686
# Rule can optionally specify if the file
87-
# should be added, modified or deleted.
88-
# For each filter there will be corresponding output variable to
87+
# should be added, modified, or deleted.
88+
# For each filter, there will be a corresponding output variable to
8989
# indicate if there's a changed file matching any of the rules.
90-
# Optionally there can be a second output variable
90+
# Optionally, there can be a second output variable
9191
# set to list of all files matching the filter.
92-
# Filters can be provided inline as a string (containing valid YAML document)
93-
# or as a relative path to separate file (e.g.: .github/filters.yaml).
94-
# Multiline string is evaluated as embedded filter definition,
95-
# single line string is evaluated as relative path to separate file.
92+
# Filters can be provided inline as a string (containing valid YAML document),
93+
# or as a relative path to a file (e.g.: .github/filters.yaml).
9694
# Filters syntax is documented by example - see examples section.
9795
filters: ''
9896
99-
# Branch, tag or commit SHA against which the changes will be detected.
100-
# If it references same branch it was pushed to,
97+
# Branch, tag, or commit SHA against which the changes will be detected.
98+
# If it references the same branch it was pushed to,
10199
# changes are detected against the most recent commit before the push.
102-
# Otherwise it uses git merge-base to find best common ancestor between
100+
# Otherwise, it uses git merge-base to find the best common ancestor between
103101
# current branch (HEAD) and base.
104102
# When merge-base is found, it's used for change detection - only changes
105-
# introduced by current branch are considered.
103+
# introduced by the current branch are considered.
106104
# All files are considered as added if there is no common ancestor with
107105
# base branch or no previous commit.
108106
# This option is ignored if action is triggered by pull_request event.
109107
# Default: repository default branch (e.g. master)
110108
base: ''
111109
112110
# Git reference (e.g. branch name) from which the changes will be detected.
113-
# Useful when workflow can be triggered only on default branch (e.g. repository_dispatch event)
114-
# but you want to get changes on different branch.
111+
# Useful when workflow can be triggered only on the default branch (e.g. repository_dispatch event)
112+
# but you want to get changes on a different branch.
115113
# This option is ignored if action is triggered by pull_request event.
116114
# default: ${{ github.ref }}
117115
ref:
118116
119-
# How many commits are initially fetched from base branch.
117+
# How many commits are initially fetched from the base branch.
120118
# If needed, each subsequent fetch doubles the
121119
# previously requested number of commits until the merge-base
122-
# is found or there are no more commits in the history.
120+
# is found, or there are no more commits in the history.
123121
# This option takes effect only when changes are detected
124122
# using git against base branch (feature branch workflow).
125123
# Default: 100
@@ -128,35 +126,35 @@ For more information see [CHANGELOG](https://github.com/dorny/paths-filter/blob/
128126
# Enables listing of files matching the filter:
129127
# 'none' - Disables listing of matching files (default).
130128
# 'csv' - Coma separated list of filenames.
131-
# If needed it uses double quotes to wrap filename with unsafe characters.
132-
# 'json' - Matching files paths are formatted as JSON array.
133-
# 'shell' - Space delimited list usable as command line argument list in Linux shell.
134-
# If needed it uses single or double quotes to wrap filename with unsafe characters.
135-
# 'escape'- Space delimited list usable as command line argument list in Linux shell.
129+
# If needed, it uses double quotes to wrap filename with unsafe characters.
130+
# 'json' - File paths are formatted as JSON array.
131+
# 'shell' - Space delimited list usable as command-line argument list in Linux shell.
132+
# If needed, it uses single or double quotes to wrap filename with unsafe characters.
133+
# 'escape'- Space delimited list usable as command-line argument list in Linux shell.
136134
# Backslash escapes every potentially unsafe character.
137135
# Default: none
138136
list-files: ''
139137
140138
# Relative path under $GITHUB_WORKSPACE where the repository was checked out.
141139
working-directory: ''
142140
143-
# Personal access token used to fetch list of changed files
141+
# Personal access token used to fetch a list of changed files
144142
# from Github REST API.
145-
# It's used only if action is triggered by pull request event.
143+
# It's only used if action is triggered by a pull request event.
146144
# Github token from workflow context is used as default value.
147-
# If empty string is provided, action falls back to detect
145+
# If an empty string is provided, the action falls back to detect
148146
# changes using git commands.
149147
# Default: ${{ github.token }}
150148
token: ''
151149
```
152150

153151
## Outputs
154-
- For each filter it sets output variable named by the filter to the text:
152+
- For each filter, it sets output variable named by the filter to the text:
155153
- `'true'` - if **any** of changed files matches any of filter rules
156154
- `'false'` - if **none** of changed files matches any of filter rules
157-
- For each filter it sets output variable with name `${FILTER_NAME}_count` to the count of matching files.
158-
- If enabled, for each filter it sets output variable with name `${FILTER_NAME}_files`. It will contain list of all files matching the filter.
159-
- `changes` - JSON array with names of all filters matching any of changed files.
155+
- For each filter, it sets an output variable with the name `${FILTER_NAME}_count` to the count of matching files.
156+
- 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.
157+
- `changes` - JSON array with names of all filters matching any of the changed files.
160158

161159
# Examples
162160

@@ -283,7 +281,7 @@ jobs:
283281
```yaml
284282
on:
285283
pull_request:
286-
branches: # PRs to following branches will trigger the workflow
284+
branches: # PRs to the following branches will trigger the workflow
287285
- master
288286
- develop
289287
jobs:
@@ -329,7 +327,7 @@ jobs:
329327
```yaml
330328
on:
331329
push:
332-
branches: # Push to following branches will trigger the workflow
330+
branches: # Push to the following branches will trigger the workflow
333331
- master
334332
- develop
335333
- release/**
@@ -341,8 +339,8 @@ jobs:
341339
- uses: dorny/paths-filter@v2
342340
id: filter
343341
with:
344-
# Use context to get branch where commits were pushed.
345-
# If there is only one long lived branch (e.g. master),
342+
# Use context to get the branch where commits were pushed.
343+
# If there is only one long-lived branch (e.g. master),
346344
# you can specify it directly.
347345
# If it's not configured, the repository default branch is used.
348346
base: ${{ github.ref }}
@@ -366,11 +364,11 @@ jobs:
366364
steps:
367365
- uses: actions/checkout@v2
368366
369-
# Some action which modifies files tracked by git (e.g. code linter)
367+
# Some action that modifies files tracked by git (e.g. code linter)
370368
- uses: johndoe/some-action@v1
371369
372370
# Filter to detect which files were modified
373-
# Changes could be for example automatically committed
371+
# Changes could be, for example, automatically committed
374372
- uses: dorny/paths-filter@v2
375373
id: filter
376374
with:
@@ -421,10 +419,10 @@ jobs:
421419
id: filter
422420
with:
423421
# Changed file can be 'added', 'modified', or 'deleted'.
424-
# By default the type of change is not considered.
425-
# Optionally it's possible to specify it using nested
426-
# dictionary, where type(s) of change composes the key.
427-
# Multiple change types can be specified using `|` as delimiter.
422+
# By default, the type of change is not considered.
423+
# Optionally, it's possible to specify it using nested
424+
# dictionary, where the type of change composes the key.
425+
# Multiple change types can be specified using `|` as the delimiter.
428426
filters: |
429427
shared: &shared
430428
- common/**
@@ -451,7 +449,7 @@ jobs:
451449
# Enable listing of files matching each filter.
452450
# Paths to files will be available in `${FILTER_NAME}_files` output variable.
453451
# Paths will be escaped and space-delimited.
454-
# Output is usable as command line argument list in Linux shell
452+
# Output is usable as command-line argument list in Linux shell
455453
list-files: shell
456454

457455
# In this example changed files will be checked by linter.
@@ -478,7 +476,7 @@ jobs:
478476
# Paths will be formatted as JSON array
479477
list-files: json
480478

481-
# In this example all changed files are passed to following action to do
479+
# In this example all changed files are passed to the following action to do
482480
# some custom processing.
483481
filters: |
484482
changed:

Diff for: action.yml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ inputs:
1313
description: |
1414
Git reference (e.g. branch name) from which the changes will be detected.
1515
This option is ignored if action is triggered by pull_request event.
16-
default: ${{ github.ref }}
1716
required: false
1817
base:
1918
description: |

0 commit comments

Comments
 (0)