[chore] Improve the Makefile to make it more robust to other environments. (#1063)

This commit is contained in:
Michael Safyan 2024-05-23 17:40:28 -05:00 committed by GitHub
parent e299079696
commit dadb51b7c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 30 additions and 5 deletions

View File

@ -16,6 +16,17 @@ CHLOGGEN_CONFIG := .chloggen/config.yaml
SEMCONVGEN_VERSION=0.24.0 SEMCONVGEN_VERSION=0.24.0
WEAVER_VERSION=0.2.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. # TODO: add `yamllint` step to `all` after making sure it works on Mac.
.PHONY: all .PHONY: all
all: install-tools markdownlint markdown-link-check misspell table-check compatibility-check schema-check \ all: install-tools markdownlint markdown-link-check misspell table-check compatibility-check schema-check \
@ -96,7 +107,7 @@ yamllint:
.PHONY: table-generation .PHONY: table-generation
table-generation: table-generation:
docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec -v $(PWD)/templates:/weaver/templates \ 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 \ --registry=/source \
--attribute-registry-base-url=/docs/attributes-registry \ --attribute-registry-base-url=/docs/attributes-registry \
--templates=/weaver/templates \ --templates=/weaver/templates \
@ -107,7 +118,7 @@ table-generation:
.PHONY: attribute-registry-generation .PHONY: attribute-registry-generation
attribute-registry-generation: attribute-registry-generation:
docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec -v $(PWD)/templates:/weaver/templates \ 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 \ --registry=/source \
--templates=/weaver/templates \ --templates=/weaver/templates \
markdown \ markdown \
@ -118,7 +129,7 @@ attribute-registry-generation:
.PHONY: table-check .PHONY: table-check
table-check: table-check:
docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec -v $(PWD)/templates:/weaver/templates \ 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 \ --registry=/source \
--attribute-registry-base-url=/docs/attributes-registry \ --attribute-registry-base-url=/docs/attributes-registry \
--templates=/weaver/templates \ --templates=/weaver/templates \
@ -126,11 +137,25 @@ table-check:
--dry-run \ --dry-run \
/spec /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 .PHONY: compatibility-check
compatibility-check: compatibility-check:
docker run --rm -v $(PWD)/model:/source -v $(PWD)/docs:/spec --pull=always \ 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 .PHONY: schema-check
schema-check: schema-check: