github.com/abayer/test-infra@v0.0.5/hack/verify-bazel.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2016 The Kubernetes Authors.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  set -o errexit
    17  set -o nounset
    18  set -o pipefail
    19  
    20  TESTINFRA_ROOT=$(git rev-parse --show-toplevel)
    21  TMP_GOPATH=$(mktemp -d)
    22  cd "${TESTINFRA_ROOT}"
    23  
    24  OUTPUT_GOBIN="${TESTINFRA_ROOT}/_output/bin"
    25  GOBIN="${OUTPUT_GOBIN}" go install ./vendor/github.com/bazelbuild/bazel-gazelle/cmd/gazelle
    26  GOBIN="${OUTPUT_GOBIN}" go install ./vendor/github.com/kubernetes/repo-infra/kazel
    27  
    28  touch "${TESTINFRA_ROOT}/vendor/BUILD.bazel"
    29  
    30  gazelle_diff=$("${OUTPUT_GOBIN}/gazelle" fix \
    31    -external=vendored \
    32    -mode=diff)
    33  
    34  kazel_diff=$("${OUTPUT_GOBIN}/kazel" \
    35    -dry-run \
    36    -print-diff)
    37  
    38  if [[ -n "${gazelle_diff}" || -n "${kazel_diff}" ]]; then
    39    echo "${gazelle_diff}"
    40    echo "${kazel_diff}"
    41    echo
    42    echo "Run ./hack/update-bazel.sh"
    43    exit 1
    44  fi
    45  
    46  # Make sure there are no BUILD files outside vendor - we should only have
    47  # BUILD.bazel files.
    48  old_build_files=$(find . -name BUILD \( -type f -o -type l \) \
    49    -not -path './vendor/*' | sort)
    50  if [[ -n "${old_build_files}" ]]; then
    51    echo "One or more BUILD files found in the tree:" >&2
    52    echo "${old_build_files}" >&2
    53    echo >&2
    54    echo "Only BUILD.bazel is allowed." >&2
    55    exit 1
    56  fi