Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions actions/changed-files/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ steps:

This will match any file in the root-level `.github` folder, unless it ends in `.md` or `.rst`.

⚠️ **Note:** When using multi-line values, make sure to use the `|-` syntax as below to eliminate trailing newlines.

```yaml
steps:
- name:
Expand Down
21 changes: 20 additions & 1 deletion actions/changed-files/check_changed_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# - INCLUDE_PATTERN
# - EXCLUDE_PATTERN

set -ex
set -e

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

trim_string() {
# source: https://github.com/dylanaraps/pure-bash-bible#trim-leading-and-trailing-white-space-from-string
# Usage: trim_string " example string "
: "${1#"${1%%[![:space:]]*}"}"
: "${_%"${_##*[![:space:]]}"}"
printf '%s\n' "$_"
}

current_branch=$(git branch --show-current)
CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT "${previous_sha}..${current_branch}")
echo "CHANGED_FILES: $CHANGED_FILES"

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

for include_pattern in "${INCLUDE_PATTERNS[@]}"; do
include_pattern=$(trim_string "${include_pattern}")
if [[ -z ${include_pattern} ]]; then
continue
fi
if [[ "${file}" =~ ${include_pattern} ]]; then
echo "including: ${file} (pattern: ${include_pattern})"
should_include=1
break
fi
done

if [[ ${should_include} -eq 1 ]] && [[ ${#EXCLUDE_PATTERNS[@]} -ne 0 ]]; then
for exclude_pattern in "${EXCLUDE_PATTERNS[@]}"; do
exclude_pattern=$(trim_string "${exclude_pattern}")
if [[ -z ${exclude_pattern} ]]; then
continue
fi
if [[ "${file}" =~ ${exclude_pattern} ]]; then
echo "excluding: ${file} (pattern: ${exclude_pattern})"
should_exclude=1
break
fi
Expand Down