|
1 | | -WORKDIR := $(shell pwd) |
2 | | -NATIVEOS := $(shell go version | awk -F '[ /]' '{print $$4}') |
3 | | -NATIVEARCH := $(shell go version | awk -F '[ /]' '{print $$5}') |
4 | | -INTEGRATION := mssql |
5 | | -BINARY_NAME = nri-$(INTEGRATION) |
6 | | -GO_FILES := ./src/ |
7 | | -GOTOOLS = github.com/kardianos/govendor \ |
8 | | - gopkg.in/alecthomas/gometalinter.v2 \ |
9 | | - github.com/axw/gocov/gocov \ |
10 | | - github.com/AlekSi/gocov-xml \ |
| 1 | +WORKDIR := $(shell pwd) |
| 2 | +INTEGRATION := mssql |
| 3 | +BINARY_NAME = nri-$(INTEGRATION) |
| 4 | +GO_FILES := ./src/ |
| 5 | +GOFLAGS = -mod=readonly |
| 6 | +GOLANGCI_LINT = github.com/golangci/golangci-lint/cmd/golangci-lint |
| 7 | +GOCOV = github.com/axw/gocov/gocov |
| 8 | +GOCOV_XML = github.com/AlekSi/gocov-xml |
11 | 9 |
|
12 | 10 | all: build |
13 | 11 |
|
14 | | -build: check-version clean validate test compile |
| 12 | +build: clean validate test compile |
15 | 13 |
|
16 | 14 | clean: |
17 | 15 | @echo "=== $(INTEGRATION) === [ clean ]: Removing binaries and coverage file..." |
18 | 16 | @rm -rfv bin coverage.xml |
19 | 17 |
|
20 | | -tools: check-version |
21 | | - @echo "=== $(INTEGRATION) === [ tools ]: Installing tools required by the project..." |
22 | | - @go get $(GOTOOLS) |
23 | | - @gometalinter.v2 --install |
| 18 | +validate: |
| 19 | + @echo "=== $(INTEGRATION) === [ validate ]: Validating source code running golangci-lint..." |
| 20 | + @go run $(GOFLAGS) $(GOLANGCI_LINT) run --verbose |
24 | 21 |
|
25 | | -tools-update: check-version |
26 | | - @echo "=== $(INTEGRATION) === [ tools-update ]: Updating tools required by the project..." |
27 | | - @go get -u $(GOTOOLS) |
28 | | - @gometalinter.v2 --install |
29 | | - |
30 | | -deps: tools deps-only |
31 | | - |
32 | | -deps-only: |
33 | | - @echo "=== $(INTEGRATION) === [ deps ]: Installing package dependencies required by the project..." |
34 | | - @govendor sync |
35 | | - |
36 | | -validate: deps |
37 | | - @echo "=== $(INTEGRATION) === [ validate ]: Validating source code running gometalinter..." |
38 | | - @gometalinter.v2 --config=.gometalinter.json $(GO_FILES)... |
39 | | - |
40 | | -validate-all: deps |
41 | | - @echo "=== $(INTEGRATION) === [ validate ]: Validating source code running gometalinter..." |
42 | | - @gometalinter.v2 --config=.gometalinter.json --enable=interfacer --enable=gosimple $(GO_FILES)... |
| 22 | +test: |
| 23 | + @echo "=== $(INTEGRATION) === [ test ]: Running unit tests..." |
| 24 | + @go run $(GOFLAGS) $(GOCOV) test ./... | go run $(GOFLAGS) $(GOCOV_XML) > coverage.xml |
43 | 25 |
|
44 | | -compile: deps |
45 | | - @echo "=== $(INTEGRATION) === [ compile ]: Building $(BINARY_NAME)..." |
46 | | - @go build -o bin/$(BINARY_NAME) $(GO_FILES) |
| 26 | +integration-test: |
| 27 | + @echo "=== $(INTEGRATION) === [ test ]: running integration tests..." |
| 28 | + @docker-compose -f tests/docker-compose.yml pull |
| 29 | + @go test -v -tags=integration ./tests/. || (ret=$$?; docker-compose -f tests/docker-compose.yml down && exit $$ret) |
| 30 | + @docker-compose -f tests/docker-compose.yml down |
47 | 31 |
|
48 | | -compile-only: deps-only |
| 32 | +compile: |
49 | 33 | @echo "=== $(INTEGRATION) === [ compile ]: Building $(BINARY_NAME)..." |
50 | 34 | @go build -o bin/$(BINARY_NAME) $(GO_FILES) |
51 | 35 |
|
52 | | -test: deps |
53 | | - @echo "=== $(INTEGRATION) === [ test ]: Running unit tests..." |
54 | | - @gocov test -race $(GO_FILES)... | gocov-xml > coverage.xml |
55 | | - |
56 | 36 | # Include thematic Makefiles |
57 | 37 | include $(CURDIR)/build/ci.mk |
58 | 38 | include $(CURDIR)/build/release.mk |
59 | 39 |
|
60 | | -check-version: |
61 | | -ifdef GOOS |
62 | | -ifneq "$(GOOS)" "$(NATIVEOS)" |
63 | | - $(error GOOS is not $(NATIVEOS). Cross-compiling is only allowed for 'clean', 'deps-only' and 'compile-only' targets) |
64 | | -endif |
65 | | -endif |
66 | | -ifdef GOARCH |
67 | | -ifneq "$(GOARCH)" "$(NATIVEARCH)" |
68 | | - $(error GOARCH variable is not $(NATIVEARCH). Cross-compiling is only allowed for 'clean', 'deps-only' and 'compile-only' targets) |
69 | | -endif |
70 | | -endif |
71 | | - |
72 | | -.PHONY: all build clean tools tools-update deps validate compile test check-version |
| 40 | +.PHONY: all build clean validate compile test |
0 commit comments