1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00
Files
opentelemetry-go/Makefile
T

292 lines
9.5 KiB
Makefile
Raw Normal View History

# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2020-09-09 12:14:03 -04:00
TOOLS_MOD_DIR := ./internal/tools
ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
2022-02-15 14:03:38 -08:00
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
OTEL_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR), $(ALL_GO_MOD_DIRS))
ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | grep -E -v '^./example|^$(TOOLS_MOD_DIR)' | sort)
2021-03-01 08:38:23 -08:00
GO = go
TIMEOUT = 60
2019-07-02 16:21:24 -07:00
.DEFAULT_GOAL := precommit
2021-03-01 08:38:23 -08:00
.PHONY: precommit ci
2023-05-23 16:30:49 +02:00
precommit: generate dependabot-generate license-check misspell go-mod-tidy golangci-lint-fix test-default
2023-05-18 16:16:29 +02:00
ci: generate dependabot-check license-check lint vanity-import-check build test-default check-clean-work-tree test-coverage
2019-06-18 17:09:49 -07:00
2021-03-01 08:38:23 -08:00
# Tools
2019-06-18 17:09:49 -07:00
2021-03-01 08:38:23 -08:00
TOOLS = $(CURDIR)/.tools
2019-06-18 17:09:49 -07:00
2021-03-01 08:38:23 -08:00
$(TOOLS):
@mkdir -p $@
$(TOOLS)/%: | $(TOOLS)
cd $(TOOLS_MOD_DIR) && \
2021-03-01 08:38:23 -08:00
$(GO) build -o $@ $(PACKAGE)
2021-10-01 16:20:32 -04:00
MULTIMOD = $(TOOLS)/multimod
$(TOOLS)/multimod: PACKAGE=go.opentelemetry.io/build-tools/multimod
2021-08-02 14:39:18 -04:00
SEMCONVGEN = $(TOOLS)/semconvgen
$(TOOLS)/semconvgen: PACKAGE=go.opentelemetry.io/build-tools/semconvgen
2021-03-01 08:38:23 -08:00
CROSSLINK = $(TOOLS)/crosslink
2022-05-06 07:40:59 -07:00
$(TOOLS)/crosslink: PACKAGE=go.opentelemetry.io/build-tools/crosslink
SEMCONVKIT = $(TOOLS)/semconvkit
$(TOOLS)/semconvkit: PACKAGE=go.opentelemetry.io/otel/$(TOOLS_MOD_DIR)/semconvkit
2022-02-17 07:45:10 -08:00
DBOTCONF = $(TOOLS)/dbotconf
2022-03-21 12:38:13 -07:00
$(TOOLS)/dbotconf: PACKAGE=go.opentelemetry.io/build-tools/dbotconf
2022-02-17 07:45:10 -08:00
2021-03-01 08:38:23 -08:00
GOLANGCI_LINT = $(TOOLS)/golangci-lint
$(TOOLS)/golangci-lint: PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint
2021-03-01 08:38:23 -08:00
MISSPELL = $(TOOLS)/misspell
2021-09-28 04:37:26 +02:00
$(TOOLS)/misspell: PACKAGE=github.com/client9/misspell/cmd/misspell
2019-07-02 16:21:24 -07:00
2021-08-14 17:10:15 +02:00
GOCOVMERGE = $(TOOLS)/gocovmerge
2021-09-28 04:37:26 +02:00
$(TOOLS)/gocovmerge: PACKAGE=github.com/wadey/gocovmerge
2021-08-14 17:10:15 +02:00
2021-03-01 08:38:23 -08:00
STRINGER = $(TOOLS)/stringer
$(TOOLS)/stringer: PACKAGE=golang.org/x/tools/cmd/stringer
2020-08-24 09:43:29 -07:00
2021-09-28 04:37:26 +02:00
PORTO = $(TOOLS)/porto
$(TOOLS)/porto: PACKAGE=github.com/jcchavezs/porto/cmd/porto
2021-10-01 16:20:32 -04:00
GOJQ = $(TOOLS)/gojq
2021-03-01 08:38:23 -08:00
$(TOOLS)/gojq: PACKAGE=github.com/itchyny/gojq/cmd/gojq
2019-07-02 16:21:24 -07:00
GOTMPL = $(TOOLS)/gotmpl
$(GOTMPL): PACKAGE=go.opentelemetry.io/build-tools/gotmpl
2023-08-14 16:42:08 +02:00
GORELEASE = $(TOOLS)/gorelease
$(GORELEASE): PACKAGE=golang.org/x/exp/cmd/gorelease
2021-03-01 08:38:23 -08:00
.PHONY: tools
2023-08-14 16:42:08 +02:00
tools: $(CROSSLINK) $(DBOTCONF) $(GOLANGCI_LINT) $(MISSPELL) $(GOCOVMERGE) $(STRINGER) $(PORTO) $(GOJQ) $(SEMCONVGEN) $(MULTIMOD) $(SEMCONVKIT) $(GOTMPL) $(GORELEASE)
2019-07-02 16:21:24 -07:00
# Virtualized python tools via docker
# The directory where the virtual environment is created.
VENVDIR := venv
# The directory where the python tools are installed.
PYTOOLS := $(VENVDIR)/bin
# The pip executable in the virtual environment.
PIP := $(PYTOOLS)/pip
# The directory in the docker image where the current directory is mounted.
WORKDIR := /workdir
# The python image to use for the virtual environment.
PYTHONIMAGE := python:3.11.3-slim-bullseye
# Run the python image with the current directory mounted.
DOCKERPY := docker run --rm -v "$(CURDIR):$(WORKDIR)" -w $(WORKDIR) $(PYTHONIMAGE)
# Create a virtual environment for Python tools.
$(PYTOOLS):
# The `--upgrade` flag is needed to ensure that the virtual environment is
# created with the latest pip version.
@$(DOCKERPY) bash -c "python3 -m venv $(VENVDIR) && $(PIP) install --upgrade pip"
# Install python packages into the virtual environment.
$(PYTOOLS)/%: | $(PYTOOLS)
@$(DOCKERPY) $(PIP) install -r requirements.txt
CODESPELL = $(PYTOOLS)/codespell
$(CODESPELL): PACKAGE=codespell
2023-05-18 16:16:29 +02:00
# Generate
2021-03-01 08:38:23 -08:00
2023-05-18 16:16:29 +02:00
.PHONY: generate
2023-05-23 16:30:49 +02:00
generate: go-generate vanity-import-fix
2022-02-15 14:03:38 -08:00
2023-05-23 16:30:49 +02:00
.PHONY: go-generate
go-generate: $(OTEL_GO_MOD_DIRS:%=go-generate/%)
go-generate/%: DIR=$*
go-generate/%: | $(STRINGER) $(GOTMPL)
2022-02-15 14:03:38 -08:00
@echo "$(GO) generate $(DIR)/..." \
&& cd $(DIR) \
2023-05-23 16:30:49 +02:00
&& PATH="$(TOOLS):$${PATH}" $(GO) generate ./...
.PHONY: vanity-import-fix
vanity-import-fix: | $(PORTO)
@$(PORTO) --include-internal -w .
2022-02-15 14:03:38 -08:00
2023-06-08 21:29:39 +02:00
# Generate go.work file for local development.
.PHONY: go-work
go-work: | $(CROSSLINK)
$(CROSSLINK) work --root=$(shell pwd)
2023-05-18 16:16:29 +02:00
# Build
.PHONY: build
build: $(OTEL_GO_MOD_DIRS:%=build/%) $(OTEL_GO_MOD_DIRS:%=build-tests/%)
2022-02-15 14:03:38 -08:00
build/%: DIR=$*
build/%:
@echo "$(GO) build $(DIR)/..." \
&& cd $(DIR) \
&& $(GO) build ./...
build-tests/%: DIR=$*
build-tests/%:
@echo "$(GO) build tests $(DIR)/..." \
&& cd $(DIR) \
&& $(GO) list ./... \
| grep -v third_party \
| xargs $(GO) test -vet=off -run xxxxxMatchNothingxxxxx >/dev/null
2019-11-22 10:48:53 -08:00
2021-03-01 08:38:23 -08:00
# Tests
2019-07-02 16:21:24 -07:00
2021-03-01 08:38:23 -08:00
TEST_TARGETS := test-default test-bench test-short test-verbose test-race
.PHONY: $(TEST_TARGETS) test
2022-02-15 14:03:38 -08:00
test-default test-race: ARGS=-race
2021-03-01 08:38:23 -08:00
test-bench: ARGS=-run=xxxxxMatchNothingxxxxx -test.benchtime=1ms -bench=.
test-short: ARGS=-short
2022-02-15 14:03:38 -08:00
test-verbose: ARGS=-v -race
2021-03-01 08:38:23 -08:00
$(TEST_TARGETS): test
2022-02-15 14:03:38 -08:00
test: $(OTEL_GO_MOD_DIRS:%=test/%)
test/%: DIR=$*
test/%:
@echo "$(GO) test -timeout $(TIMEOUT)s $(ARGS) $(DIR)/..." \
&& cd $(DIR) \
&& $(GO) list ./... \
| grep -v third_party \
| xargs $(GO) test -timeout $(TIMEOUT)s $(ARGS)
2020-09-25 13:27:03 -07:00
2021-03-01 08:38:23 -08:00
COVERAGE_MODE = atomic
COVERAGE_PROFILE = coverage.out
.PHONY: test-coverage
2021-08-14 17:10:15 +02:00
test-coverage: | $(GOCOVMERGE)
2021-03-01 08:38:23 -08:00
@set -e; \
printf "" > coverage.txt; \
for dir in $(ALL_COVERAGE_MOD_DIRS); do \
2021-08-14 17:10:15 +02:00
echo "$(GO) test -coverpkg=go.opentelemetry.io/otel/... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_PROFILE)" $${dir}/..."; \
2021-03-01 08:38:23 -08:00
(cd "$${dir}" && \
$(GO) list ./... \
| grep -v third_party \
| grep -v 'semconv/v.*' \
| xargs $(GO) test -coverpkg=./... -covermode=$(COVERAGE_MODE) -coverprofile="$(COVERAGE_PROFILE)" && \
$(GO) tool cover -html=coverage.out -o coverage.html); \
2021-03-01 08:38:23 -08:00
done; \
2021-08-14 17:10:15 +02:00
$(GOCOVMERGE) $$(find . -name coverage.out) > coverage.txt
2021-03-01 08:38:23 -08:00
2022-02-15 14:03:38 -08:00
.PHONY: golangci-lint golangci-lint-fix
golangci-lint-fix: ARGS=--fix
golangci-lint-fix: golangci-lint
golangci-lint: $(OTEL_GO_MOD_DIRS:%=golangci-lint/%)
golangci-lint/%: DIR=$*
golangci-lint/%: | $(GOLANGCI_LINT)
@echo 'golangci-lint $(if $(ARGS),$(ARGS) ,)$(DIR)' \
&& cd $(DIR) \
&& $(GOLANGCI_LINT) run --allow-serial-runners $(ARGS)
.PHONY: crosslink
crosslink: | $(CROSSLINK)
2022-05-06 07:40:59 -07:00
@echo "Updating intra-repository dependencies in all go modules" \
&& $(CROSSLINK) --root=$(shell pwd) --prune
2022-02-15 14:03:38 -08:00
.PHONY: go-mod-tidy
go-mod-tidy: $(ALL_GO_MOD_DIRS:%=go-mod-tidy/%)
go-mod-tidy/%: DIR=$*
go-mod-tidy/%: | crosslink
@echo "$(GO) mod tidy in $(DIR)" \
&& cd $(DIR) \
2023-09-07 10:18:29 -07:00
&& $(GO) mod tidy -compat=1.20
2022-02-15 14:03:38 -08:00
.PHONY: lint-modules
lint-modules: go-mod-tidy
2019-11-27 11:27:41 -08:00
.PHONY: lint
2022-02-15 14:03:38 -08:00
lint: misspell lint-modules golangci-lint
2021-03-01 08:38:23 -08:00
2021-09-28 04:37:26 +02:00
.PHONY: vanity-import-check
vanity-import-check: | $(PORTO)
@$(PORTO) --include-internal -l . || ( echo "(run: make vanity-import-fix)"; exit 1 )
2022-04-20 11:12:02 -07:00
2021-03-01 08:38:23 -08:00
.PHONY: misspell
misspell: | $(MISSPELL)
2022-02-15 14:03:38 -08:00
@$(MISSPELL) -w $(ALL_DOCS)
.PHONY: codespell
codespell: | $(CODESPELL)
@$(DOCKERPY) $(CODESPELL)
.PHONY: license-check
license-check:
2022-04-29 08:22:10 -07:00
@licRes=$$(for f in $$(find . -type f \( -iname '*.go' -o -iname '*.sh' \) ! -path '**/third_party/*' ! -path './.git/*' ) ; do \
awk '/Copyright The OpenTelemetry Authors|generated|GENERATED/ && NR<=4 { found=1; next } END { if (!found) print FILENAME }' $$f; \
done); \
if [ -n "$${licRes}" ]; then \
echo "license header checking failed:"; echo "$${licRes}"; \
exit 1; \
fi
2020-08-26 16:34:41 -07:00
2022-03-21 12:38:13 -07:00
DEPENDABOT_CONFIG = .github/dependabot.yml
2020-08-26 16:34:41 -07:00
.PHONY: dependabot-check
2022-03-21 12:38:13 -07:00
dependabot-check: | $(DBOTCONF)
@$(DBOTCONF) verify $(DEPENDABOT_CONFIG) || ( echo "(run: make dependabot-generate)"; exit 1 )
2021-03-01 08:38:23 -08:00
2022-02-17 07:45:10 -08:00
.PHONY: dependabot-generate
2022-03-21 12:38:13 -07:00
dependabot-generate: | $(DBOTCONF)
@$(DBOTCONF) generate > $(DEPENDABOT_CONFIG)
2022-02-17 07:45:10 -08:00
2021-03-01 08:38:23 -08:00
.PHONY: check-clean-work-tree
check-clean-work-tree:
@if ! git diff --quiet; then \
echo; \
echo 'Working tree is not clean, did you forget to run "make precommit"?'; \
echo; \
git status; \
exit 1; \
fi
2021-10-01 16:20:32 -04:00
SEMCONVPKG ?= "semconv/"
.PHONY: semconv-generate
semconv-generate: | $(SEMCONVGEN) $(SEMCONVKIT)
2023-07-26 17:09:04 +02:00
[ "$(TAG)" ] || ( echo "TAG unset: missing opentelemetry semantic-conventions tag"; exit 1 )
[ "$(OTEL_SEMCONV_REPO)" ] || ( echo "OTEL_SEMCONV_REPO unset: missing path to opentelemetry semantic-conventions repo"; exit 1 )
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=span -p conventionType=trace -f trace.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=attribute_group -p conventionType=trace -f attribute_group.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=event -p conventionType=event -f event.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=resource -p conventionType=resource -f resource.go -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
2023-01-06 14:30:32 -08:00
$(SEMCONVKIT) -output "$(SEMCONVPKG)/$(TAG)" -tag "$(TAG)"
2023-08-14 16:42:08 +02:00
.PHONY: gorelease
gorelease: $(OTEL_GO_MOD_DIRS:%=gorelease/%)
gorelease/%: DIR=$*
gorelease/%:| $(GORELEASE)
@echo "gorelease in $(DIR):" \
&& cd $(DIR) \
&& $(GORELEASE) \
|| echo ""
2021-10-01 16:20:32 -04:00
.PHONY: prerelease
prerelease: | $(MULTIMOD)
@[ "${MODSET}" ] || ( echo ">> env var MODSET is not set"; exit 1 )
$(MULTIMOD) verify && $(MULTIMOD) prerelease -m ${MODSET}
COMMIT ?= "HEAD"
.PHONY: add-tags
add-tags: | $(MULTIMOD)
@[ "${MODSET}" ] || ( echo ">> env var MODSET is not set"; exit 1 )
$(MULTIMOD) verify && $(MULTIMOD) tag -m ${MODSET} -c ${COMMIT}