diff --git a/.circleci/config.yml b/.circleci/config.yml index b139a90af..8f30525ab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,7 @@ jobs: - run: name: "Precommit and Coverage Report" command: | - make circle-ci + make ci mv coverage.html $TEST_RESULTS/ - save_cache: diff --git a/Makefile b/Makefile index ac7a547b7..60d9b536d 100644 --- a/Makefile +++ b/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_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort) -GOTEST=go test -GOTEST_OPT?=-v -timeout 30s -GOTEST_OPT_WITH_RACE = $(GOTEST_OPT) -race -GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic +GOTEST_MIN = go test -v -timeout 30s +GOTEST = $(GOTEST_MIN) -race +GOTEST_WITH_COVERAGE = $(GOTEST) -coverprofile=coverage.txt -covermode=atomic .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 go build -o $(TOOLS_DIR)/stringer golang.org/x/tools/cmd/stringer -precommit: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell $(TOOLS_DIR)/stringer - PATH="$(abspath $(TOOLS_DIR)):$${PATH}" go generate ./... +precommit: lint generate build examples test + +.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. set -e; for dir in $(ALL_GO_MOD_DIRS); do \ echo "compiling all packages in $${dir}"; \ @@ -36,6 +59,33 @@ precommit: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell $(TOOLS_DIR)/string go build ./... && \ go test -run xxxxxMatchNothingxxxxx ./... >/dev/null); \ 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 \ echo "golangci-lint in $${dir}"; \ (cd "$${dir}" && \ @@ -48,57 +98,5 @@ precommit: $(TOOLS_DIR)/golangci-lint $(TOOLS_DIR)/misspell $(TOOLS_DIR)/string go mod tidy); \ done -.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) $(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 +generate: + PATH="$(abspath $(TOOLS_DIR)):$${PATH}" go generate ./...