Skip to content

Commit cdeee37

Browse files
committed
fix protoc generation
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 0ef12e2 commit cdeee37

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
14+
- uses: asdf-vm/actions/install@v3
1415
- name: Set up JDK
1516
uses: actions/setup-java@v4
1617
with:
1718
java-version: 17
1819
distribution: temurin
1920
cache: 'maven'
20-
- name: Install Protoc
21-
run: |
22-
VERSION=28.2
23-
curl -sL -o protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v$VERSION/protoc-$VERSION-linux-x86_64.zip
24-
sudo unzip protoc.zip -d /usr/local
2521
- name: Run the Maven verify phase
2622
env:
2723
PROTO_GENERATION: true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
protoc 28.3

prometheus-metrics-exposition-formats/generate-protobuf.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,33 @@ set -euo pipefail
88
TARGET_DIR=$1
99
PROTO_DIR=src/main/protobuf
1010
PROTOBUF_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

1415
rm -rf TARGET_DIR || true
1516
mkdir -p $TARGET_DIR
1617
rm -rf $PROTO_DIR || true
1718
mkdir -p $PROTO_DIR
1819

1920
curl -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
2123
protoc --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
3139
fi
40+

0 commit comments

Comments
 (0)