@@ -8,24 +8,33 @@ set -euo pipefail
88TARGET_DIR=$1
99PROTO_DIR=src/main/protobuf
1010PROTOBUF_VERSION_STRING=$2
11+ PROTOBUF_VERSION=" ${PROTOBUF_VERSION_STRING// _/ .} "
1112
12- echo " Generating protobuf sources for version $PROTOBUF_VERSION_STRING in $TARGET_DIR "
13+ echo " Generating protobuf sources for version $PROTOBUF_VERSION in $TARGET_DIR "
1314
1415rm -rf TARGET_DIR || true
1516mkdir -p $TARGET_DIR
1617rm -rf $PROTO_DIR || true
1718mkdir -p $PROTO_DIR
1819
1920curl -sL https://raw.githubusercontent.com/prometheus/client_model/master/io/prometheus/client/metrics.proto -o $PROTO_DIR /metrics.proto
20- sed -i " s/java_package = \" io.prometheus.client\" /java_package = \" io.prometheus.metrics.expositionformats.generated.com_google_protobuf_${PROTOBUF_VERSION_STRING} \" /" $PROTO_DIR /metrics.proto
21+ PACKAGE=" io.prometheus.metrics.expositionformats.generated.com_google_protobuf_${PROTOBUF_VERSION_STRING} "
22+ sed -i " s/java_package = \" io.prometheus.client\" /java_package = \" $PACKAGE \" /" $PROTO_DIR /metrics.proto
2123protoc --java_out $TARGET_DIR $PROTO_DIR /metrics.proto
2224
23- # stop the build if there class is not up-to-date
24- # show local changes
25- DIFF=$( git diff)
26- if [[ ${REQUIRE_PROTO_UP_TO_DATE:- false} == " true" && -n " $DIFF " ]]; then
25+ GENERATED_WITH=$( grep -oP ' \/\/ Protobuf Java Version: \K.*' " $TARGET_DIR /${PACKAGE// \. // } " /Metrics.java)
26+
27+ if [[ $GENERATED_WITH != " $PROTOBUF_VERSION " ]]; then
28+ echo " Generated protobuf sources version $GENERATED_WITH does not match provided version $PROTOBUF_VERSION "
29+ echo " Please update the protoc version .tool-versions to the latest version of https://github.com/protocolbuffers/protobuf/releases"
30+ exit 1
31+ fi
32+
33+ STATUS=$( git status --porcelain)
34+ if [[ ${REQUIRE_PROTO_UP_TO_DATE:- false} == " true" && -n " $STATUS " ]]; then
2735 echo " Generated protobuf sources are not up-to-date. Please run 'PROTO_GENERATION=true mvn clean install' and commit the changes."
2836 echo " Local changes:"
29- echo " $DIFF "
37+ echo " $STATUS "
3038 exit 1
3139fi
40+
0 commit comments