From 98d75be82f10f047f6558e2d02a11eb73d88b125 Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Fri, 14 Feb 2025 18:02:57 -0800 Subject: [PATCH] Rework changed-files test (doc-only, container-only) Take an array of patterns to compare each changed file against. For docs, use the current suggestions from https://tracker.ceph.com/issues/69650 Signed-off-by: Dan Mick --- scripts/build_utils.sh | 44 +++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/scripts/build_utils.sh b/scripts/build_utils.sh index 0100c34a..c4c5d6d6 100755 --- a/scripts/build_utils.sh +++ b/scripts/build_utils.sh @@ -1686,10 +1686,12 @@ maybe_reset_ci_container() { # 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 @@ -1703,20 +1705,44 @@ pr_only_for() { 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() { -- 2.39.5