# NOTE: These functions will only work on a Pull Request job!
pr_only_for() {
- local egrep_pattern=$1
-
+ # $1 is passed by reference to avoid having to call with ${array[@]} and
+ # receive by creating another local array ("$@")
+ local -n local_patterns=$1
+ local files
pushd .
- # Only try to cd to ceph repo if we need to.
+ # cd to ceph repo if we need to.
# The ceph-pr-commits job checks out ceph.git and ceph-build.git but most
# other jobs do not.
if ! [[ "$(git config --get remote.origin.url)" =~ "ceph/ceph.git" ]]; then
fi
popd
echo -e "changed files:\n$files"
- if [ $(echo "$files" | egrep -v $egrep_pattern | wc -l) -gt 0 ]; then
- return 1
- fi
- return 0
+ # 0 is true, 1 is false
+ local all_match=0
+ for f in $files; do
+ local match=1
+ for p in "${local_patterns[@]}"; do
+ # pattern loop: if one pattern matches, skip the others
+ if [[ $f == $p ]]; then match=0; break; fi
+ done
+ # file loop: if this file matched no patterns, the group fails
+ # (one mismatch spoils the whole bushel)
+ if [[ $match -eq 1 ]] ; then all_match=1; break; fi
+ done
+ return $all_match
}
docs_pr_only() {
DOCS_ONLY=false
- if pr_only_for '^(doc/|admin/)'; then DOCS_ONLY=true; fi
+ local patterns=(
+ 'doc/*'
+ 'admin/*'
+ 'src/sample.ceph.conf'
+ 'CodingStyle'
+ '*.rst'
+ '*.md'
+ 'COPYING*'
+ 'README.*'
+ 'SubmittingPatches'
+ '.readthedocs.yml'
+ )
+ if pr_only_for patterns; then DOCS_ONLY=true; fi
}
container_pr_only() {
CONTAINER_ONLY=false
- if pr_only_for '^container/'; then CONTAINER_ONLY=true; fi
+ local patterns=(
+ 'container/*'
+ )
+ if pr_only_for patterns; then CONTAINER_ONLY=true; fi
}
function ssh_exec() {