From 43d85f6595e5981afc1e477c34b899918fce2a09 Mon Sep 17 00:00:00 2001 From: Michael Aaron Safyan Date: Wed, 22 May 2024 15:29:48 -0400 Subject: [PATCH] Improve the Makefile to make it more robust to other environments. --- Makefile | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 88a484eccb..1b6b4f499d 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,17 @@ CHLOGGEN_CONFIG := .chloggen/config.yaml SEMCONVGEN_VERSION=0.24.0 WEAVER_VERSION=0.2.0 +# From where to resolve the containers (e.g. "otel/weaver"). +CONTAINER_REPOSITORY=docker.io + +# Per container overrides for the repository resolution. +WEAVER_CONTAINER_REPOSITORY=$(CONTAINER_REPOSITORY) +SEMCONVGEN_CONTAINER_REPOSITORY=$(CONTAINER_REPOSITORY) + +# Fully qualified references to containers used in this Makefile. +WEAVER_CONTAINER=$(WEAVER_CONTAINER_REPOSITORY)/otel/weaver:$(WEAVER_VERSION) +SEMCONVGEN_CONTAINER=$(SEMCONVGEN_CONTAINER_REPOSITORY)/otel/semconvgen:$(SEMCONVGEN_VERSION) + # TODO: add `yamllint` step to `all` after making sure it works on Mac. .PHONY: all all: install-tools markdownlint markdown-link-check misspell table-check compatibility-check schema-check \ @@ -96,7 +107,7 @@ yamllint: .PHONY: table-generation table-generation: docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec -v $(PWD)/templates:/weaver/templates \ - otel/weaver:${WEAVER_VERSION} registry update-markdown \ + $(WEAVER_CONTAINER) registry update-markdown \ --registry=/source \ --attribute-registry-base-url=/docs/attributes-registry \ --templates=/weaver/templates \ @@ -107,7 +118,7 @@ table-generation: .PHONY: attribute-registry-generation attribute-registry-generation: docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec -v $(PWD)/templates:/weaver/templates \ - otel/weaver:${WEAVER_VERSION} registry generate \ + $(WEAVER_CONTAINER) registry generate \ --registry=/source \ --templates=/weaver/templates \ markdown \ @@ -118,7 +129,7 @@ attribute-registry-generation: .PHONY: table-check table-check: docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec -v $(PWD)/templates:/weaver/templates \ - otel/weaver:${WEAVER_VERSION} registry update-markdown \ + $(WEAVER_CONTAINER) registry update-markdown \ --registry=/source \ --attribute-registry-base-url=/docs/attributes-registry \ --templates=/weaver/templates \ @@ -126,11 +137,25 @@ table-check: --dry-run \ /spec -LATEST_RELEASED_SEMCONV_VERSION := $(shell git describe --tags --abbrev=0 | sed 's/v//g') + +# A previous iteration of calculating "LATEST_RELEASED_SEMCONV_VERSION" +# relied on "git describe". However, that approach does not work with +# light-weight developer forks/branches that haven't synced tags. Hence the +# more complex implementation of this using "git ls-remote". +# +# The output of "git ls-remote" looks something like this: +# +# e531541025992b68177a68b87628c5dc75c4f7d9 refs/tags/v1.21.0 +# cadfe53949266d33476b15ca52c92f682600a29c refs/tags/v1.22.0 +# ... +# +# .. which is why some additional processing is required to extract the +# latest version number and strip off the "v" prefix. +LATEST_RELEASED_SEMCONV_VERSION := $(shell git ls-remote --tags https://github.com/open-telemetry/semantic-conventions.git | cut -f 2 | sort --reverse | head -n 1 | tr '/' ' ' | cut -d ' ' -f 3 | sed 's/v//g') .PHONY: compatibility-check compatibility-check: docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec --pull=always \ - otel/semconvgen:$(SEMCONVGEN_VERSION) -f /source compatibility --previous-version $(LATEST_RELEASED_SEMCONV_VERSION) + $(SEMCONVGEN_CONTAINER) -f /source compatibility --previous-version $(LATEST_RELEASED_SEMCONV_VERSION) .PHONY: schema-check schema-check: