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

107 lines
3.2 KiB
Makefile
Raw Normal View History

EXAMPLES := $(shell ./get_main_pkgs.sh ./example)
TOOLS_MOD_DIR := ./tools
# All source code and documents. Used in spell check.
ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
# All directories with go.mod files related to opentelemetry library. Used for building, testing and linting.
ALL_GO_MOD_DIRS := $(filter-out $(TOOLS_MOD_DIR), $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort))
ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | egrep -v '^./example|^$(TOOLS_MOD_DIR)' | sort)
2019-11-27 11:27:41 -08:00
GOTEST_MIN = go test -v -timeout 30s
GOTEST = $(GOTEST_MIN) -race
GOTEST_WITH_COVERAGE = $(GOTEST) -coverprofile=coverage.txt -covermode=atomic
2019-07-02 16:21:24 -07:00
.DEFAULT_GOAL := precommit
2019-06-18 17:09:49 -07:00
.PHONY: precommit
TOOLS_DIR := $(abspath ./.tools)
2019-06-18 17:09:49 -07:00
$(TOOLS_DIR)/golangci-lint: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go
cd $(TOOLS_MOD_DIR) && \
2019-06-18 17:09:49 -07:00
go build -o $(TOOLS_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
$(TOOLS_DIR)/misspell: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go
cd $(TOOLS_MOD_DIR) && \
go build -o $(TOOLS_DIR)/misspell github.com/client9/misspell/cmd/misspell
$(TOOLS_DIR)/stringer: $(TOOLS_MOD_DIR)/go.mod $(TOOLS_MOD_DIR)/go.sum $(TOOLS_MOD_DIR)/tools.go
cd $(TOOLS_MOD_DIR) && \
go build -o $(TOOLS_DIR)/stringer golang.org/x/tools/cmd/stringer
2020-01-24 21:06:24 +01:00
precommit: generate build lint examples test
2019-07-02 16:21:24 -07:00
.PHONY: test-with-coverage
test-with-coverage:
set -e; for dir in $(ALL_COVERAGE_MOD_DIRS); do \
echo "go test ./... + coverage in $${dir}"; \
(cd "$${dir}" && \
2019-11-27 11:27:41 -08:00
$(GOTEST_WITH_COVERAGE) ./... && \
go tool cover -html=coverage.txt -o coverage.html); \
done
2019-07-02 16:21:24 -07:00
2019-11-27 11:27:41 -08:00
.PHONY: ci
ci: precommit check-clean-work-tree test-with-coverage test-386
2019-11-27 11:27:41 -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
2019-07-02 16:21:24 -07:00
2019-11-27 11:27:41 -08:00
.PHONY: build
build:
# TODO: Fix this on windows.
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
2019-11-27 11:27:41 -08:00
echo "compiling all packages in $${dir}"; \
(cd "$${dir}" && \
2019-11-27 11:27:41 -08:00
go build ./... && \
go test -run xxxxxMatchNothingxxxxx ./... >/dev/null); \
done
2019-07-02 16:21:24 -07:00
2019-11-27 11:27:41 -08:00
.PHONY: test
test:
2019-11-22 10:48:53 -08:00
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
2019-11-27 11:27:41 -08:00
echo "go test ./... + race in $${dir}"; \
2019-11-22 10:48:53 -08:00
(cd "$${dir}" && \
2019-11-27 11:27:41 -08:00
$(GOTEST) ./...); \
2019-11-22 10:48:53 -08:00
done
2019-07-02 16:21:24 -07:00
.PHONY: test-386
test-386:
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
echo "go test ./... GOARCH 386 in $${dir}"; \
(cd "$${dir}" && \
2019-11-27 11:27:41 -08:00
GOARCH=386 $(GOTEST_MIN) ./...); \
done
2019-07-02 16:21:24 -07:00
.PHONY: examples
examples:
@set -e; for ex in $(EXAMPLES); do \
echo "Building $${ex}"; \
(cd "$${ex}" && \
go build .); \
done
2019-11-27 11:27:41 -08:00
.PHONY: lint
2020-01-24 21:06:24 +01:00
lint: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell
2019-11-27 11:27:41 -08:00
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
echo "golangci-lint in $${dir}"; \
(cd "$${dir}" && \
$(TOOLS_DIR)/golangci-lint run --fix && \
$(TOOLS_DIR)/golangci-lint run); \
2019-11-27 11:27:41 -08:00
done
$(TOOLS_DIR)/misspell -w $(ALL_DOCS)
set -e; for dir in $(ALL_GO_MOD_DIRS) $(TOOLS_MOD_DIR); do \
2019-11-27 11:27:41 -08:00
echo "go mod tidy in $${dir}"; \
(cd "$${dir}" && \
go mod tidy); \
done
2020-01-24 21:06:24 +01:00
generate: $(TOOLS_DIR)/stringer
PATH="$(TOOLS_DIR):$${PATH}" go generate ./...