go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/proto/googleapis/import.sh (about) 1 #!/bin/bash 2 # Copyright 2023 The LUCI 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 set -e 16 17 # List of proto files within https://github.com/googleapis/googleapis to import. 18 PROTOS_TO_IMPORT=( 19 google/api/annotations.proto 20 google/api/client.proto 21 google/api/field_behavior.proto 22 google/api/field_info.proto 23 google/api/http.proto 24 google/api/launch_stage.proto 25 google/api/resource.proto 26 27 google/cloud/security/privateca/v1/resources.proto 28 29 google/rpc/code.proto 30 google/rpc/error_details.proto 31 google/rpc/status.proto 32 33 google/type/color.proto 34 google/type/date.proto 35 google/type/dayofweek.proto 36 google/type/expr.proto 37 google/type/latlng.proto 38 google/type/money.proto 39 google/type/postal_address.proto 40 google/type/timeofday.proto 41 ) 42 43 cd $(dirname "${BASH_SOURCE[0]}") 44 45 # Clear existing imported files. 46 rm -rf google 47 48 # Get pinned version of googleapis that the version of 49 # google.golang.org/genproto in go.mod pins. 50 genproto_version=$(grep "google.golang.org/genproto" ../../../go.sum | grep -v go.mod | awk '{print $2}' | sort -V | tail -n1) 51 genproto_mod_dir=$(go mod download -json google.golang.org/genproto | \ 52 python3 -c "import sys, json; print(json.load(sys.stdin)['Dir'])") 53 googleapis_version=$(cat "${genproto_mod_dir}/regen.txt") 54 55 echo "using googleapis hash: ${googleapis_version}" 56 57 # Grab the most recent checkout of "googleapis" repo. 58 CHECKOUT=".googleapis_checkout" 59 mkdir -p ${CHECKOUT} 60 pushd ${CHECKOUT} 61 git init 62 git remote rm origin || true 63 git remote add origin https://github.com/googleapis/googleapis 64 git config extensions.partialclone origin 65 git config remote.origin.fetch +refs/heads/master:refs/remotes/origin/master 66 git config remote.origin.partialclonefilter blob:none 67 git config pull.rebase true 68 git fetch origin 69 git pull origin --depth 1 ${googleapis_version} 70 git checkout origin/master 71 REVISION=$(git rev-parse HEAD) 72 popd 73 74 # Copy all requested files + LICENSE + revision information. 75 for PROTO in ${PROTOS_TO_IMPORT[*]} 76 do 77 mkdir -p $(dirname ${PROTO}) 78 cp "${CHECKOUT}/${PROTO}" ${PROTO} 79 done 80 cp "${CHECKOUT}/LICENSE" google/ 81 echo "${REVISION}" > google/REVISION 82 echo "${genproto_version}" > google/GENPROTO_REGEN 83 84 # Make sure all dependencies are copied too by trying to compile everything. 85 set +e 86 echo 87 echo "Compiling all imported files to make sure their dependencies exist..." 88 echo 89 protoc --proto_path=. --descriptor_set_out=/dev/null ${PROTOS_TO_IMPORT[*]} 90 if [ $? -ne 0 ]; then 91 echo 92 echo "protoc call failed. Examine its output and add missing *.proto files" 93 echo "to PROTOS_TO_IMPORT. Keep doing that until it no longer complains." 94 echo 95 echo "DO NOT IGNORE THIS ERROR!" 96 exit 1 97 fi 98 rm -rf ${CHECKOUT} 99 echo "Success!"