@@ -29,26 +29,34 @@ steps:
2929
3030 git fetch --unshallow
3131 git diff origin/${_BASE_BRANCH} --name-only > _changed_files
32- sed 's/\/.*/\//' _changed_files > _changed_folders
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"
38+ _INFRA_FOLDERS="build test/ .github/" TODO: fix build/, remove github?
3639 for d in _changed_folders; do
3740 if [[ "${_INFRA_FOLDERS}" =~ "$d" ]]; then
3841 echo "Infrastructure folders have changed; no tests will be pruned."
3942 exit 0 # do not prune
4043 fi
4144 done
4245
43- for d in */; do
44- if ! grep -q "^$d" _changed_folders && [[ "$d" != "test/" ]]; then
46+ # Remove leaf folders without changes
47+ # TODO: Handle intermeidate folders that also contain .tf
48+ for d in `find . -type d -name 'test' -prune -o -links 2 -printf '%P\n'`; do
49+ if ! grep -q "^$d" _changed_folders; then
4550 rm -rf $d;
4651 fi
4752 done
4853
54+ # Remove any empty folders
55+ find . -empty -type d -delete
56+
4957 # Report remaining folders
5058 echo Folders in scope for tests:
51- for d in */; do echo $d; done
59+ find . -type d -printf '%P\n'
5260
5361 - id : prepare
5462 name : ' gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
0 commit comments