github.com/munnerz/test-infra@v0.0.0-20190108210205-ce3d181dc989/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  cd $(git rev-parse --show-toplevel)
    21  
    22  deprecated-verify() {
    23    OUTPUT_GOBIN="./_output/bin"
    24    GOBIN="${OUTPUT_GOBIN}" go install ./vendor/github.com/bazelbuild/bazel-gazelle/cmd/gazelle
    25    GOBIN="${OUTPUT_GOBIN}" go install ./vendor/github.com/kubernetes/repo-infra/kazel
    26    gazelle_diff=$("${OUTPUT_GOBIN}/gazelle" fix \
    27      -external=vendored \
    28      -mode=diff)
    29  
    30    kazel_diff=$("${OUTPUT_GOBIN}/kazel" \
    31      -dry-run \
    32      -print-diff\
    33      --cfg-path=./hack/.kazelcfg.json)
    34  
    35  }
    36  
    37  mkdir -p ./vendor
    38  touch ./vendor/BUILD.bazel
    39  
    40  if ! which bazel &> /dev/null; then
    41    echo "Bazel is the preferred way to build and test the test-infra repo." >&2
    42    echo "Please install bazel at https://bazel.build/ (future commits may require it)" >&2
    43    deprecated-verify
    44  else
    45    gazelle_diff=$(bazel run //:gazelle-diff)
    46    kazel_diff=$(bazel run //:kazel-diff)
    47  fi
    48  
    49  if [[ -n "${gazelle_diff}" || -n "${kazel_diff}" ]]; then
    50    echo "${gazelle_diff}"
    51    echo "${kazel_diff}"
    52    echo
    53    echo "Run ./hack/update-bazel.sh"
    54    exit 1
    55  fi
    56  
    57  # Make sure there are no BUILD files outside vendor - we should only have
    58  # BUILD.bazel files.
    59  old_build_files=$(find . -name BUILD \( -type f -o -type l \) \
    60    -not -path './vendor/*' | sort)
    61  if [[ -n "${old_build_files}" ]]; then
    62    echo "One or more BUILD files found in the tree:" >&2
    63    echo "${old_build_files}" >&2
    64    echo >&2
    65    echo "Only BUILD.bazel is allowed." >&2
    66    exit 1
    67  fi