Skip to content

Commit 79e416c

Browse files
committed
changed-files: ignore empty patterns
1 parent 37d464f commit 79e416c

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

actions/changed-files/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ steps:
3434
3535
This will match any file in the root-level `.github` folder, unless it ends in `.md` or `.rst`.
3636

37-
⚠️ **Note:** When using multi-line values, make sure to use the `|-` syntax as below to eliminate trailing newlines.
38-
3937
```yaml
4038
steps:
4139
- name:

actions/changed-files/check_changed_files.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# - INCLUDE_PATTERN
44
# - EXCLUDE_PATTERN
55

6-
set -ex
6+
set -e
77

88
if [[ -z "${GITHUB_BASE_REF}" ]]; then
99
# this is not a pull request event, just get the previous commit
@@ -12,8 +12,17 @@ else
1212
previous_sha="origin/${GITHUB_BASE_REF}"
1313
fi
1414

15+
trim_string() {
16+
# source: https://github.com/dylanaraps/pure-bash-bible#trim-leading-and-trailing-white-space-from-string
17+
# Usage: trim_string " example string "
18+
: "${1#"${1%%[![:space:]]*}"}"
19+
: "${_%"${_##*[![:space:]]}"}"
20+
printf '%s\n' "$_"
21+
}
22+
1523
current_branch=$(git branch --show-current)
1624
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT "${previous_sha}..${current_branch}")
25+
echo "CHANGED_FILES: $CHANGED_FILES"
1726

1827
readarray -t INCLUDE_PATTERNS < <(echo "${INCLUDE_PATTERN}")
1928
readarray -t EXCLUDE_PATTERNS < <(echo "${EXCLUDE_PATTERN}")
@@ -23,15 +32,25 @@ while IFS= read -r file; do
2332
should_exclude=0
2433

2534
for include_pattern in "${INCLUDE_PATTERNS[@]}"; do
35+
include_pattern=$(trim_string "${include_pattern}")
36+
if [[ -z ${include_pattern} ]]; then
37+
continue
38+
fi
2639
if [[ "${file}" =~ ${include_pattern} ]]; then
40+
echo "including: ${file} (pattern: ${include_pattern})"
2741
should_include=1
2842
break
2943
fi
3044
done
3145

3246
if [[ ${should_include} -eq 1 ]] && [[ ${#EXCLUDE_PATTERNS[@]} -ne 0 ]]; then
3347
for exclude_pattern in "${EXCLUDE_PATTERNS[@]}"; do
48+
exclude_pattern=$(trim_string "${exclude_pattern}")
49+
if [[ -z ${exclude_pattern} ]]; then
50+
continue
51+
fi
3452
if [[ "${file}" =~ ${exclude_pattern} ]]; then
53+
echo "excluding: ${file} (pattern: ${exclude_pattern})"
3554
should_exclude=1
3655
break
3756
fi
@@ -43,4 +62,4 @@ while IFS= read -r file; do
4362
fi
4463
done <<<"${CHANGED_FILES}"
4564

46-
echo "all_changed_files=${MATCHED_FILES[*]}" | tee -a "${GITHUB_OUTPUT}"
65+
echo "all_changed_files=${MATCHED_FILES[*]}" #| tee -a "${GITHUB_OUTPUT}"

0 commit comments

Comments
 (0)