From 22d61e4c3a94d6809ec76e7c06c113c89ae8f869 Mon Sep 17 00:00:00 2001 From: Evan Torrie Date: Mon, 13 Jul 2020 21:36:30 -0700 Subject: [PATCH 1/4] Add protogen workflow --- .github/workflows/protogen.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/protogen.yml diff --git a/.github/workflows/protogen.yml b/.github/workflows/protogen.yml new file mode 100644 index 00000000000..e526f17be99 --- /dev/null +++ b/.github/workflows/protogen.yml @@ -0,0 +1,23 @@ +name: Proto-go-generator +on: + pull_request: + paths: + - 'internal/opentelemetry-proto' + +jobs: + protogen: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + submodules: true + - uses: actions/setup-go@v2 + with: + go-version: '^1.14.0' + - run: sudo apt-get -y install pax + - run: make -f Makefile.proto protobuf + - uses: stefanzweifel/git-auto-commit-action@v4 + id: commit-changes + with: + commit_message: Commit changes in updated/new protobuf files From aed8cd7e5c0cffdb6bc2dea5809b444d9fe4f979 Mon Sep 17 00:00:00 2001 From: Evan Torrie Date: Tue, 14 Jul 2020 10:57:08 -0700 Subject: [PATCH 2/4] Move out protobuf generation to Makefile.proto --- Makefile | 2 +- Makefile.proto | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 Makefile.proto diff --git a/Makefile b/Makefile index 8a23adab081..3cf4a3e70d5 100644 --- a/Makefile +++ b/Makefile @@ -143,7 +143,7 @@ generate: $(TOOLS_DIR)/stringer .PHONY: license-check license-check: - @licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path './vendor/*') ; do \ + @licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path './vendor/*' ! -path './internal/opentelemetry-proto/*') ; do \ awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=3 { found=1; next } END { if (!found) print FILENAME }' $$f; \ done); \ if [ -n "$${licRes}" ]; then \ diff --git a/Makefile.proto b/Makefile.proto new file mode 100644 index 00000000000..cd0ebeee35c --- /dev/null +++ b/Makefile.proto @@ -0,0 +1,71 @@ +# Copyright The OpenTelemetry Authors -*- mode: makefile; -*- +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This Makefile.proto has rules to generate *.pb.go files in +# `internal/opentelemetry-proto-gen` from the .proto files in +# `internal/opentelemetry-proto` using protoc with a go plugin. +# +# The protoc binary and other tools are sourced from a docker +# image `PROTOC_IMAGE`. +# +# Prereqs: The archiving utility `pax` is installed. + +PROTOC_IMAGE := namely/protoc-all:1.29_2 +PROTOBUF_VERSION := v1 +OTEL_PROTO_SUBMODULE := internal/opentelemetry-proto +PROTOBUF_GEN_DIR := internal/opentelemetry-proto-gen +PROTOBUF_TEMP_DIR := gen/pb-go +PROTO_SOURCE_DIR := gen/proto +SUBMODULE_PROTO_FILES := $(wildcard $(OTEL_PROTO_SUBMODULE)/opentelemetry/proto/*/$(PROTOBUF_VERSION)/*.proto \ + $(OTEL_PROTO_SUBMODULE)/opentelemetry/proto/collector/*/$(PROTOBUF_VERSION)/*.proto) +SOURCE_PROTO_FILES := $(subst $(OTEL_PROTO_SUBMODULE),$(PROTO_SOURCE_DIR),$(SUBMODULE_PROTO_FILES)) + +default: protobuf + +.PHONY: protobuf protobuf-source gen-protobuf copy-protobufs +protobuf: protobuf-source gen-protobuf copy-protobufs + +protobuf-source: $(SOURCE_PROTO_FILES) | $(PROTO_SOURCE_DIR)/ + +# Changes go_package in .proto file to point to repo-local location +define exec-replace-pkgname +sed 's,go_package = "github.com/open-telemetry/opentelemetry-proto/gen/go,go_package = "go.opentelemetry.io/otel/internal/opentelemetry-proto-gen,' < $(1) > $(2) + +endef + +# replace opentelemetry-proto package name by go.opentelemetry.io/otel specific version +$(SOURCE_PROTO_FILES): $(PROTO_SOURCE_DIR)/%.proto: $(OTEL_PROTO_SUBMODULE)/%.proto + @mkdir -p $(@D) + $(call exec-replace-pkgname,$<,$@) + +# Command to run protoc using docker image +define exec-protoc-all +docker run -v `pwd`:/defs $(PROTOC_IMAGE) $(1) + +endef + +gen-protobuf: $(SOURCE_PROTO_FILES) | $(PROTOBUF_GEN_DIR)/ + $(foreach file,$(subst ${PROTO_SOURCE_DIR}/,,$(SOURCE_PROTO_FILES)),$(call exec-protoc-all, -i $(PROTO_SOURCE_DIR) -f ${file} -l go -o ${PROTOBUF_TEMP_DIR})) + +# requires `pax` to be installed, as it has consistent options for both BSD (Darwin) and Linux +copy-protobufs: | $(PROTOBUF_GEN_DIR)/ + find ./$(PROTOBUF_TEMP_DIR)/go.opentelemetry.io/otel/$(PROTOBUF_GEN_DIR) -type f -print0 | \ + pax -0 -s ',^./$(PROTOBUF_TEMP_DIR)/go.opentelemetry.io/otel/$(PROTOBUF_GEN_DIR),,' -rw ./$(PROTOBUF_GEN_DIR) + +$(PROTO_SOURCE_DIR)/ $(PROTOBUF_GEN_DIR)/: + mkdir -p $@ + +.PHONY: clean +clean: + rm -rf ./gen From 6db2fcedc2c0802a29cefb0a98f1f570b7d5c4ef Mon Sep 17 00:00:00 2001 From: Evan Torrie Date: Tue, 14 Jul 2020 13:53:12 -0700 Subject: [PATCH 3/4] Include in Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55fc2e8e72e..589b75fce7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased] +### Added + +- Github action to generate protobuf Go bindings locally in `internal/opentelemetry-proto-gen`. (#938) + ## [0.8.0] - 2020-07-09 ### Added From b2b48a3cd338153a340d677a98e66af355e00c4d Mon Sep 17 00:00:00 2001 From: ET Date: Thu, 16 Jul 2020 10:03:51 -0700 Subject: [PATCH 4/4] Update Makefile.proto Move file-local mode variable to line by itself. Co-authored-by: Tyler Yahn --- Makefile.proto | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.proto b/Makefile.proto index cd0ebeee35c..68662514563 100644 --- a/Makefile.proto +++ b/Makefile.proto @@ -1,4 +1,5 @@ -# Copyright The OpenTelemetry Authors -*- mode: makefile; -*- +# -*- mode: makefile; -*- +# Copyright The OpenTelemetry Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.