Skip to content

Commit 65c262b

Browse files
apeabodyglasnt
andauthored
chore(CI): directory specific test change pruning (#669)
* chore(CI): directory specific test change pruning --------- Co-authored-by: Katie McLaughlin <[email protected]>
1 parent 3346881 commit 65c262b

File tree

12 files changed

+18
-12
lines changed

12 files changed

+18
-12
lines changed

.github/.keep

Whitespace-only changes.

build/int.cloudbuild.yaml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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'

composer/.keep

Whitespace-only changes.

compute/.keep

Whitespace-only changes.

dns/.keep

Whitespace-only changes.

eventarc/.keep

Whitespace-only changes.

functions/.keep

Whitespace-only changes.

gke/standard/regional/labels/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# [START gke_standard_regional_labels_cluster]
1919
resource "google_container_cluster" "default" {
2020
name = "gke-standard-regional-labels"
21-
location = "us-west1"
21+
location = "us-central1"
2222
initial_node_count = 2
2323

2424
resource_labels = {

lb/.keep

Whitespace-only changes.

run/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)