Skip to content

Commit

Permalink
Now using fnmatch.fnmatch instead of Path.match for ignored glo…
Browse files Browse the repository at this point in the history
…bs (#10)

- Is more reliable at ignoring paths

---------

Co-authored-by: Adam Talbot <12817534+adamrtalbot@users.noreply.github.com>
  • Loading branch information
GallVp and adamrtalbot authored Aug 8, 2024
1 parent 6e67b7a commit 7c8be3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
root: testrepo/test
head: change_module_a
base: main
ignored: "./modules/a/*"
ignored: "modules/a/*"

- name: Do not return workflows
id: do_not_return_workflows
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ steps:
### Ignoring paths
You may want to ignore paths such as docs, strings etc. To do this, specify a list of strings separated by spaces. This supports globbing so use `*` to match multiple.
You may want to ignore paths such as docs, strings etc. To do this, specify a list of strings separated by spaces. This supports globbing so use `*` to match multiple. Python [fnmatch.fnmatch](https://docs.python.org/3/library/fnmatch.html) is used for matching the ignored paths. Here are some examples:

Note: specifying a filename (e.g. `main.nf`) will match all instances of `main.nf`, regardless of directory. If you wish to match a path in the root of the directory use a relative path (`./main.nf`).
- `.git/*`: Ignore all files and directories inside the `.git` directory
- `.gitpod.yml`: Ignore `.gitpod.yml` file in the root directory
- `*.md`: Ignore all the Markdown files
- `tests/local/*`: Ignore all files and directories inside the `tests/local/` directory

Do not use the relative path (`./`) at the start of the glob pattern as it will nullify the glob matching.

```yaml
steps:
Expand Down
12 changes: 11 additions & 1 deletion entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from enum import Enum
from git import Repo
from pathlib import Path
import fnmatch


class TestTargetType(Enum):
Expand Down Expand Up @@ -421,8 +422,17 @@ def find_changed_files(
for file in diff_index:
# Get pathlib.Path object
filepath = Path(file.a_path)
logging.debug(f"File found in diff_index: {str(filepath)}")

# If file does not match any in the ignore list, add containing directory to changed_files
if not any(filepath.match(ignored_path) for ignored_path in ignore):
match_against_ignored = []
for ignored_path in ignore:
is_matched = fnmatch.fnmatch(str(filepath), ignored_path)
logging.debug(
f"Checking match of {str(filepath)} against {str(ignored_path)}: {str(is_matched)}"
)
match_against_ignored.append(is_matched)
if not any(match_against_ignored):
# Prepend the root of the path for better scanning
changed_files.append(path.joinpath(filepath).resolve())

Expand Down

0 comments on commit 7c8be3f

Please sign in to comment.