#!/usr/bin/env bash set -uo pipefail echo "Verifying controller-generated code is visible to Bazel." array=() while IFS='' read -r line; do array+=("$line"); done < <(find . -type f -name 'zz_generated.*.go') for FILE in "${array[@]}" do DIR=${FILE%/*} BASE_DIRECTORY=./$(echo "$DIR" | cut -d "/" -f2) echo "File directory: $DIR" echo "Base directory: $BASE_DIRECTORY" # Run at least once. Feeling lucky? RULE=$(bazel run --config=quiet //hack/tools:buildozer -- 'print kind' "//$DIR:all"| grep 'gen_code') if [ -z "$RULE" ]; then # You weren't lucky. Now we have to iterate up the tree. Woomp. while [[ "$BASE_DIRECTORY" != "$DIR" ]]; do # Up the tree one and trying again. DIR="$(dirname "$DIR")" echo "Updated directory: $DIR" RULE=$(bazel run --config=quiet //hack/tools:buildozer -- 'print kind' "//$DIR:all"| grep 'gen_code') if [ -z "$RULE" ]; then # Still not found. Go to the beginning of the while loop to go up the tree once. continue else # Exit current for loop iteration since gen_code was found! echo "Managed controller generated code for: $FILE" echo "Generated in: $RULE" continue 2 fi done # Execute on base directory once. RULE=$(bazel run --config=quiet //hack/tools:buildozer -- 'print kind' "//$BASE_DIRECTORY:all"| grep 'gen_code') if [ -z "$RULE" ]; then echo "Unmanaged Controller-Generated code for: $FILE" exit 1 else # Better late than never. echo "Managed controller-generated code for: $FILE" echo "Generated in base: $BASE_DIRECTORY" fi else # You were lucky. Found on the first try. Nice. echo "Managed controller generated code for: $FILE" echo "Generated in: $RULE" continue fi done