From cc595987c0e4dde8cf50a6dd8143b4352adf0c6f Mon Sep 17 00:00:00 2001 From: Janik K <10290002+led0nk@users.noreply.github.com> Date: Thu, 6 Jun 2024 18:52:35 +0200 Subject: [PATCH] [CI] make update-otel (#32038) **Description:** Seems like there were some bugs, which i wasn't very sure about. It ran the `multimod` cmd with the wrong directory (at least in my case). On top of that i had to remove the `--commit-hash` flag, because per definition it already gets the main branch, but you should have to insert a commit-hash. If not used at all it should just be the latest. Therefore `OTEL_VERSION` and `OTEL_STABLE_VERSION` could be removed or could later on be used to get the latest commit-hash (but has to be implemented). The core-versions in `otelcontribcol/builder-config.yaml` and `oteltestbedcol/builder-config.yaml` will be updated by using `sed`. But these additional lines will only replace sth like: `v0.97.1-0.20240327181407-1038b67c85a0` and update it to: `v0.98.0` So if someone needs any kind of specific version-hash, he still would have to change this manually. This definitely is not a perfect solution for this issue (it just works :sweat_smile: ) , so just tell me if there is something totally stupid in this code. **Link to tracking Issue:** - Resolves #21632 **Testing:** **Documentation:** --------- Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- Makefile | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index eecf031ec8ee..7e5b042f40a8 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,9 @@ OTEL_VERSION=main OTEL_STABLE_VERSION=main VERSION=$(shell git describe --always --match "v[0-9]*" HEAD) +TRIMMED_VERSION=$(shell grep -o 'v[^-]*' <<< "$(VERSION)" | cut -c 2-) +CORE_VERSIONS=$(SRC_PARENT_DIR)/opentelemetry-collector/versions.yaml +GOMOD=$(SRC_ROOT)/go.mod COMP_REL_PATH=cmd/otelcontribcol/components.go MOD_NAME=github.com/open-telemetry/opentelemetry-collector-contrib @@ -344,13 +347,44 @@ telemetrygen: cd ./cmd/telemetrygen && GO111MODULE=on CGO_ENABLED=0 $(GOCMD) build -trimpath -o ../../bin/telemetrygen_$(GOOS)_$(GOARCH)$(EXTENSION) \ -tags $(GO_BUILD_TAGS) . +# helper function to update the core packages in builder-config.yaml +# input parameters are +# $(1) = path/to/versions.yaml (where it greps the relevant packages) +# $(2) = path/to/go.mod (where it greps the package-versions) +# $(3) = path/to/builder-config.yaml (where we want to update the versions) +define updatehelper + if [ ! -f $(1) ] || [ ! -f $(2) ] || [ ! -f $(3) ]; then \ + echo "Usage: updatehelper "; \ + exit 1; \ + fi + grep "go\.opentelemetry\.io" $(1) | sed 's/^\s*-\s*//' | while IFS= read -r line; do \ + if grep -qF "$$line" $(2); then \ + package=$$(grep -F "$$line" $(2) | head -n 1 | awk '{print $$1}'); \ + version=$$(grep -F "$$line" $(2) | head -n 1 | awk '{print $$2}'); \ + builder_package=$$(grep -F "$$package" $(3) | awk '{print $$3}'); \ + builder_version=$$(grep -F "$$package" $(3) | awk '{print $$4}'); \ + if [ "$$builder_package" == "$$package" ]; then \ + echo "$$builder_version";\ + sed -i -e "s|$$builder_package.*$$builder_version|$$builder_package $$version|" $(3); \ + echo "[$(3)]: $$package updated to $$version"; \ + fi; \ + fi; \ + done +endef + + .PHONY: update-otel update-otel:$(MULTIMOD) $(MULTIMOD) sync -s=true -o ../opentelemetry-collector -m stable --commit-hash $(OTEL_STABLE_VERSION) - git add . && git commit -s -m "[chore] multimod update stable modules" + git add . && git commit -s -m "[chore] multimod update stable modules" ; \ $(MULTIMOD) sync -s=true -o ../opentelemetry-collector -m beta --commit-hash $(OTEL_VERSION) - git add . && git commit -s -m "[chore] multimod update beta modules" + git add . && git commit -s -m "[chore] multimod update beta modules" ; \ + $(call updatehelper,$(CORE_VERSIONS),$(GOMOD),./cmd/otelcontribcol/builder-config.yaml) + $(call updatehelper,$(CORE_VERSIONS),$(GOMOD),./cmd/oteltestbedcol/builder-config.yaml) $(MAKE) gotidy + $(MAKE) genotelcontribcol + $(MAKE) genoteltestbedcol + $(MAKE) oteltestbedcol .PHONY: otel-from-tree otel-from-tree: