Skip to content

Commit

Permalink
[CI] make update-otel (open-telemetry#32038)
Browse files Browse the repository at this point in the history
**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 open-telemetry#21632 

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>

---------

Co-authored-by: Alex Boten <[email protected]>
  • Loading branch information
led0nk and codeboten authored Jun 6, 2024
1 parent 314b731 commit cc59598
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <versions.yaml> <go.mod> <builder-config.yaml>"; \
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:
Expand Down

0 comments on commit cc59598

Please sign in to comment.