github.com/GoogleCloudPlatform/testgrid@v0.0.174/hack/verify-protos.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2019 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 if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel 21 echo "Checking protos for changes..." >&2 22 elif ! command -v bazel &>/dev/null; then 23 echo "Install bazel at https://bazel.build" >&2 24 exit 1 25 else 26 ( 27 set -o xtrace 28 bazel test //hack:verify-protos 29 ) 30 exit 0 31 fi 32 33 TESTINFRA_ROOT=$PWD 34 35 _tmpdir="$(mktemp -d -t verify-deps.XXXXXX)" 36 trap "rm -rf ${_tmpdir}" EXIT 37 38 cp -a "${TESTINFRA_ROOT}/." "${_tmpdir}" 39 40 # Update protos, outputting to $_tmpdir 41 ( 42 update_protos=$1 43 protoc=$2 44 plugin=$3 45 boiler=$4 46 grpc=$5 47 importmap=$6 48 49 export _virtual_imports=$TEST_SRCDIR/com_google_protobuf/_virtual_imports 50 export BUILD_WORKSPACE_DIRECTORY=${_tmpdir} 51 "$update_protos" "$protoc" "$plugin" "$boiler" "$grpc" "$importmap" 52 ) 53 54 55 # Ensure nothing changed 56 diff=$(diff -Nupr \ 57 -x ".git" \ 58 -x "bazel-*" \ 59 -x "_output" \ 60 "${TESTINFRA_ROOT}" "${_tmpdir}" 2>/dev/null || true) 61 62 if [[ -n "${diff}" ]]; then 63 echo "${diff}" >&2 64 echo >&2 65 echo "ERROR: protos changed. Run bazel run //hack:update-protos" >&2 66 exit 1 67 fi