33# - INCLUDE_PATTERN
44# - EXCLUDE_PATTERN
55
6- set -ex
6+ set -e
77
88if [[ -z " ${GITHUB_BASE_REF} " ]]; then
99 # this is not a pull request event, just get the previous commit
1212 previous_sha=" origin/${GITHUB_BASE_REF} "
1313fi
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+
1523current_branch=$( git branch --show-current)
1624CHANGED_FILES=$( git diff --name-only --diff-filter=ACMRT " ${previous_sha} ..${current_branch} " )
25+ echo " CHANGED_FILES: $CHANGED_FILES "
1726
1827readarray -t INCLUDE_PATTERNS < <( echo " ${INCLUDE_PATTERN} " )
1928readarray -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
4463done <<< " ${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