...

Text file src/edge-infra.dev/hack/verify/controller-gen-targets.sh

Documentation: edge-infra.dev/hack/verify

     1#!/usr/bin/env bash
     2
     3set -uo pipefail
     4
     5echo "Verifying controller-generated code is visible to Bazel."
     6
     7array=()
     8while IFS='' read -r line; do array+=("$line"); done < <(find . -type f -name 'zz_generated.*.go')
     9
    10for FILE in "${array[@]}"
    11do
    12    DIR=${FILE%/*}
    13    BASE_DIRECTORY=./$(echo "$DIR" | cut -d "/" -f2)
    14    echo "File directory: $DIR"
    15    echo "Base directory: $BASE_DIRECTORY"
    16
    17    # Run at least once. Feeling lucky?
    18    RULE=$(bazel run --config=quiet //hack/tools:buildozer -- 'print kind' "//$DIR:all"| grep 'gen_code')
    19
    20    if [ -z "$RULE" ]; then
    21      # You weren't lucky. Now we have to iterate up the tree. Woomp.
    22      while [[ "$BASE_DIRECTORY" != "$DIR" ]]; do
    23        # Up the tree one and trying again.
    24        DIR="$(dirname "$DIR")"
    25        echo "Updated directory: $DIR"
    26        RULE=$(bazel run --config=quiet //hack/tools:buildozer -- 'print kind' "//$DIR:all"| grep 'gen_code')
    27
    28        if [ -z "$RULE" ]; then
    29          # Still not found. Go to the beginning of the while loop to go up the tree once.
    30          continue
    31        else
    32          # Exit current for loop iteration since gen_code was found!
    33          echo "Managed controller generated code for: $FILE"
    34          echo "Generated in: $RULE"
    35          continue 2
    36        fi
    37      done
    38
    39      # Execute on base directory once.
    40      RULE=$(bazel run --config=quiet //hack/tools:buildozer -- 'print kind' "//$BASE_DIRECTORY:all"| grep 'gen_code')
    41      if [ -z "$RULE" ]; then
    42        echo "Unmanaged Controller-Generated code for: $FILE"
    43        exit 1
    44      else
    45        # Better late than never.
    46        echo "Managed controller-generated code for: $FILE"
    47        echo "Generated in base: $BASE_DIRECTORY"
    48       fi
    49    else
    50      # You were lucky. Found on the first try. Nice.
    51      echo "Managed controller generated code for: $FILE"
    52      echo "Generated in: $RULE"
    53      continue
    54    fi
    55done

View as plain text