forked from open-telemetry/opentelemetry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproto_codegen_json.sh
More file actions
executable file
·59 lines (48 loc) · 1.8 KB
/
Copy pathproto_codegen_json.sh
File metadata and controls
executable file
·59 lines (48 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
#
# Regenerate python code from OTLP protos in
# https://github.com/open-telemetry/opentelemetry-proto
#
# To use, update PROTO_REPO_BRANCH_OR_COMMIT variable below to a commit hash or
# tag in opentelemtry-proto repo that you want to build off of. Then, just run
# this script to update the proto files. Commit the changes as well as any
# fixes needed in the OTLP exporter.
#
# Optional envars:
# PROTO_REPO_DIR - the path to an existing checkout of the opentelemetry-proto repo
# Pinned commit/branch/tag for the current version used in opentelemetry-proto python package.
PROTO_REPO_BRANCH_OR_COMMIT="v1.10.0"
set -e
PROTO_REPO_DIR=${PROTO_REPO_DIR:-"/tmp/opentelemetry-proto"}
# root of opentelemetry-python repo
repo_root="$(git rev-parse --show-toplevel)"
protoc() {
uvx -c $repo_root/gen-requirements.txt \
--python 3.12 \
--from grpcio-tools \
--with "$repo_root/codegen/opentelemetry-codegen-json" \
python -m grpc_tools.protoc "$@"
}
protoc --version
# Clone the proto repo if it doesn't exist
if [ ! -d "$PROTO_REPO_DIR" ]; then
git clone https://github.com/open-telemetry/opentelemetry-proto.git $PROTO_REPO_DIR
fi
# Pull in changes and switch to requested branch
(
cd $PROTO_REPO_DIR
git fetch --all
git checkout $PROTO_REPO_BRANCH_OR_COMMIT
# pull if PROTO_REPO_BRANCH_OR_COMMIT is not a detached head
git symbolic-ref -q HEAD && git pull --ff-only || true
)
cd $repo_root/opentelemetry-proto-json/src
# clean up old generated code
find opentelemetry/proto_json/ -name "*.py" -delete
# generate proto code for all protos
all_protos=$(find $PROTO_REPO_DIR/ -iname "*.proto")
protoc \
-I $PROTO_REPO_DIR \
--otlp_json_out=. \
$all_protos
echo "Please update ./opentelemetry-proto-json/README.rst to include the updated version."