@@ -28,27 +28,33 @@ steps:
2828 fi
2929
3030 git fetch --unshallow
31- git diff origin/${_BASE_BRANCH} --name-only > _changed_files
32- sed 's/\/.*/\//' _changed_files > _changed_folders
31+ git diff origin/main --name-only > _changed_files
32+ sed 's:[^/]*$::' _changed_files > _changed_folders
33+ sort -u -o _changed_folders{,}
34+ echo Folders with changes:
35+ cat _changed_folders
3336
3437 # Do not prune if changing tests themselves
35- _INFRA_FOLDERS="build test .github"
36- for d in _changed_folders; do
37- if [[ "${_INFRA_FOLDERS}" =~ "$d" ]]; then
38- echo "Infrastructure folders have changed; no tests will be pruned."
38+ while read d; do
39+ if [[ "build test .github" =~ "${d%/}" ]]; then
40+ echo "Infrastructure folder ${d%/} has changed; no tests will be pruned."
3941 exit 0 # do not prune
4042 fi
41- done
43+ done < _changed_folders
4244
43- for d in */; do
44- if ! grep -q "^$d" _changed_folders && [[ "$d" != "test/" ]]; then
45- rm -rf $d;
45+ # Remove leaf folders without changes or non-tf resources
46+ for d in `find . -type d -name 'test' -prune -o -links 2 -printf '%P\n'`; do
47+ if ! grep -q "^$d" _changed_folders && ! [ -n "$(find $d -maxdepth 1 -not -name '*.tf' -type f -print -quit)" ]; then
48+ rm -rf $d
4649 fi
4750 done
4851
52+ # Remove any empty folders
53+ find . -empty -type d -delete
54+
4955 # Report remaining folders
5056 echo Folders in scope for tests:
51- for d in */; do echo $d; done
57+ find . -type d -printf '%P\n'
5258
5359 - id : prepare
5460 name : ' gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
0 commit comments