mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-02-13 13:48:28 +02:00
Simplify Makefile (#354)
* Simplify Makefile In particular, this change: * Ensures that the race checker is always used for all tests * Removes redundant commands * Splits out `generate` and `lint` as their own commands * Renames the `circle-ci` command to the more generic `ci` * Use GOTEST_WITH_COVERAGE instead of old name * Fix test-with-coverage command * Fix test-386 command
This commit is contained in:
parent
77543cd80e
commit
e6d725626d
@ -18,7 +18,7 @@ jobs:
|
|||||||
- run:
|
- run:
|
||||||
name: "Precommit and Coverage Report"
|
name: "Precommit and Coverage Report"
|
||||||
command: |
|
command: |
|
||||||
make circle-ci
|
make ci
|
||||||
mv coverage.html $TEST_RESULTS/
|
mv coverage.html $TEST_RESULTS/
|
||||||
|
|
||||||
- save_cache:
|
- save_cache:
|
||||||
|
118
Makefile
118
Makefile
@ -7,10 +7,9 @@ ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
|
|||||||
# All directories with go.mod files. Used in go mod tidy.
|
# All directories with go.mod files. Used in go mod tidy.
|
||||||
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
|
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
|
||||||
|
|
||||||
GOTEST=go test
|
GOTEST_MIN = go test -v -timeout 30s
|
||||||
GOTEST_OPT?=-v -timeout 30s
|
GOTEST = $(GOTEST_MIN) -race
|
||||||
GOTEST_OPT_WITH_RACE = $(GOTEST_OPT) -race
|
GOTEST_WITH_COVERAGE = $(GOTEST) -coverprofile=coverage.txt -covermode=atomic
|
||||||
GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic
|
|
||||||
|
|
||||||
.DEFAULT_GOAL := precommit
|
.DEFAULT_GOAL := precommit
|
||||||
|
|
||||||
@ -27,8 +26,32 @@ $(TOOLS_DIR)/misspell: go.mod go.sum tools.go
|
|||||||
$(TOOLS_DIR)/stringer: go.mod go.sum tools.go
|
$(TOOLS_DIR)/stringer: go.mod go.sum tools.go
|
||||||
go build -o $(TOOLS_DIR)/stringer golang.org/x/tools/cmd/stringer
|
go build -o $(TOOLS_DIR)/stringer golang.org/x/tools/cmd/stringer
|
||||||
|
|
||||||
precommit: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell $(TOOLS_DIR)/stringer
|
precommit: lint generate build examples test
|
||||||
PATH="$(abspath $(TOOLS_DIR)):$${PATH}" go generate ./...
|
|
||||||
|
.PHONY: test-with-coverage
|
||||||
|
test-with-coverage:
|
||||||
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||||
|
echo "go test ./... + coverage in $${dir}"; \
|
||||||
|
(cd "$${dir}" && \
|
||||||
|
$(GOTEST_WITH_COVERAGE) ./... && \
|
||||||
|
go tool cover -html=coverage.txt -o coverage.html); \
|
||||||
|
done
|
||||||
|
|
||||||
|
.PHONY: ci
|
||||||
|
ci: precommit check-clean-work-tree test-with-coverage test-386
|
||||||
|
|
||||||
|
.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
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
build:
|
||||||
# TODO: Fix this on windows.
|
# TODO: Fix this on windows.
|
||||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||||
echo "compiling all packages in $${dir}"; \
|
echo "compiling all packages in $${dir}"; \
|
||||||
@ -36,6 +59,33 @@ precommit: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell $(TOOLS_DIR)/string
|
|||||||
go build ./... && \
|
go build ./... && \
|
||||||
go test -run xxxxxMatchNothingxxxxx ./... >/dev/null); \
|
go test -run xxxxxMatchNothingxxxxx ./... >/dev/null); \
|
||||||
done
|
done
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||||
|
echo "go test ./... + race in $${dir}"; \
|
||||||
|
(cd "$${dir}" && \
|
||||||
|
$(GOTEST) ./...); \
|
||||||
|
done
|
||||||
|
|
||||||
|
.PHONY: test-386
|
||||||
|
test-386:
|
||||||
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||||
|
echo "go test ./... GOARCH 386 in $${dir}"; \
|
||||||
|
(cd "$${dir}" && \
|
||||||
|
GOARCH=386 $(GOTEST_MIN) ./...); \
|
||||||
|
done
|
||||||
|
|
||||||
|
.PHONY: examples
|
||||||
|
examples:
|
||||||
|
@set -e; for ex in $(EXAMPLES); do \
|
||||||
|
echo "Building $${ex}"; \
|
||||||
|
(cd "$${ex}" && \
|
||||||
|
go build .); \
|
||||||
|
done
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
|
lint: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell $(TOOLS_DIR)/stringer
|
||||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
||||||
echo "golangci-lint in $${dir}"; \
|
echo "golangci-lint in $${dir}"; \
|
||||||
(cd "$${dir}" && \
|
(cd "$${dir}" && \
|
||||||
@ -48,57 +98,5 @@ precommit: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell $(TOOLS_DIR)/string
|
|||||||
go mod tidy); \
|
go mod tidy); \
|
||||||
done
|
done
|
||||||
|
|
||||||
.PHONY: test-with-coverage
|
generate:
|
||||||
test-with-coverage:
|
PATH="$(abspath $(TOOLS_DIR)):$${PATH}" go generate ./...
|
||||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
|
||||||
echo "go test ./... + coverage in $${dir}"; \
|
|
||||||
(cd "$${dir}" && \
|
|
||||||
$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) ./... && \
|
|
||||||
go tool cover -html=coverage.txt -o coverage.html); \
|
|
||||||
done
|
|
||||||
|
|
||||||
.PHONY: circle-ci
|
|
||||||
circle-ci: precommit test-clean-work-tree test-with-coverage test-race test-386 examples
|
|
||||||
|
|
||||||
.PHONY: test-clean-work-tree
|
|
||||||
test-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
|
|
||||||
|
|
||||||
.PHONY: test
|
|
||||||
test: examples
|
|
||||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
|
||||||
echo "go test ./... + race in $${dir}"; \
|
|
||||||
(cd "$${dir}" && \
|
|
||||||
$(GOTEST) $(GOTEST_OPT) ./... && \
|
|
||||||
$(GOTEST) $(GOTEST_OPT_WITH_RACE) ./...); \
|
|
||||||
done
|
|
||||||
|
|
||||||
.PHONY: test-race
|
|
||||||
test-race:
|
|
||||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
|
||||||
echo "go test -race ./... in $${dir}"; \
|
|
||||||
(cd "$${dir}" && \
|
|
||||||
$(GOTEST) $(GOTEST_OPT_WITH_RACE) ./...); \
|
|
||||||
done
|
|
||||||
|
|
||||||
.PHONY: test-386
|
|
||||||
test-386:
|
|
||||||
set -e; for dir in $(ALL_GO_MOD_DIRS); do \
|
|
||||||
echo "go test ./... GOARCH 386 in $${dir}"; \
|
|
||||||
(cd "$${dir}" && \
|
|
||||||
GOARCH=386 $(GOTEST) -v -timeout 30s ./...); \
|
|
||||||
done
|
|
||||||
|
|
||||||
.PHONY: examples
|
|
||||||
examples:
|
|
||||||
@set -e; for ex in $(EXAMPLES); do \
|
|
||||||
echo "Building $${ex}"; \
|
|
||||||
(cd "$${ex}" && \
|
|
||||||
go build .); \
|
|
||||||
done
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user