diff --git a/Makefile b/Makefile index 7c1906f4..bfeaa365 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,14 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 -SCHEMA_FILES := $(shell find . -path './schema_out/*.json' -exec basename {} \; | sort) +include validator/Makefile + EXAMPLE_FILES := $(shell find . -path './examples/*.yaml' -exec basename {} \; | sort) $(shell mkdir -p out) .PHONY: all all: install-tools compile-schema validate-examples all-meta-schema -include validator/Makefile - -.PHONY: compile-schema -compile-schema: - @if ! npm ls minimatch yaml; then npm install; fi - npm run-script yaml-to-json || exit 1; - @if ! npm ls ajv-cli; then npm install; fi - @for f in $(SCHEMA_FILES); do \ - npx --no ajv-cli compile --spec=draft2020 --allow-matching-properties -s ./schema_out/$$f -r "./schema_out/!($$f)" \ - || exit 1; \ - done - .PHONY: validate-examples validate-examples: @if ! npm ls ajv-cli; then npm install; fi diff --git a/Makefile.common b/Makefile.common new file mode 100644 index 00000000..ee308009 --- /dev/null +++ b/Makefile.common @@ -0,0 +1,14 @@ +# Copyright The OpenTelemetry Authors +# SPDX-License-Identifier: Apache-2.0 + +SCHEMA_FILES := $(shell find . -path './schema_out/*.json' -exec basename {} \; | sort) + +.PHONY: compile-schema +compile-schema: + @if ! npm ls minimatch yaml; then npm install; fi + npm run-script yaml-to-json || exit 1; + @if ! npm ls ajv-cli; then npm install; fi + @for f in $(SCHEMA_FILES); do \ + npx --no ajv-cli compile --spec=draft2020 --allow-matching-properties -s ./schema_out/$$f -r "./schema_out/!($$f)" \ + || exit 1; \ + done diff --git a/validator/Makefile b/validator/Makefile index d6bc690a..bfe9c275 100644 --- a/validator/Makefile +++ b/validator/Makefile @@ -1,6 +1,8 @@ # Copyright The OpenTelemetry Authors # SPDX-License-Identifier: Apache-2.0 +include Makefile.common + ROOT_DIR :=$(realpath $(shell dirname $(lastword $(MAKEFILE_LIST)))) PARENT_DIR :=$(realpath ${ROOT_DIR}/../) CURRENT_GIT_REF :=$(shell git rev-parse --short HEAD) @@ -32,7 +34,7 @@ $(TOOLS)/govulncheck: PACKAGE=golang.org/x/vuln/cmd/govulncheck .PHONY: tools tools: $(GOVULNCHECK) -validator-copy-schema: +validator-copy-schema: compile-schema mkdir -p ${ROOT_DIR}/schema find ${PARENT_DIR} -path '*/schema_out/*.json' ! -path '*/validator/schema/*.json' -exec cp '{}' "${ROOT_DIR}/schema/" ';'