blob: c96261731e9f35b5c31116c6e0343b8fb8c0ef11 [file] [log] [blame]
iomodo838bd5c2021-03-21 15:37:03 +04001GO ?= $(shell command -v go 2> /dev/null)
2GO_TEST_FLAGS ?= -race
3
4export GO111MODULE=on
5
6MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
7MINIMUM_SUPPORTED_GO_MINOR_VERSION = 14
8GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
9GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
10GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)
11
12BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)"
13
14## Define the default target (make all)
15.PHONY: default
16default: all
17
18## Checks the code style, tests, runs the code.
19.PHONY: all
20all: check-style test run
21
22## Runs eslint and golangci-lint
23.PHONY: check-style
24check-style:
25 @if ! [ -x "$$(command -v golangci-lint)" ]; then \
26 echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
27 exit 1; \
28 fi; \
29
30 @echo Running golangci-lint
31 golangci-lint run ./...
32
33## Runs unit tests.
34.PHONY: test
35test:
36 @echo Running unit tests
37 $(GO) test -v $(GO_TEST_FLAGS) ./...
38
39## Creates a coverage report
40.PHONY: coverage
41coverage:
42 $(GO) test $(GO_TEST_FLAGS) -coverprofile=coverage.txt ./...
43 $(GO) tool cover -html=coverage.txt
44
45## Clean removes all artifacts.
46.PHONY: clean
47clean:
48 rm -fr coverage.txt
49 rm -fr server.log
50
51.PHONY: run
52run: validate-go-version
53 @echo Running Knowledge Graph services
54
55 $(GO) run ./cmd/
56
57.PHONY: validate-go-version
58validate-go-version: ## Validates the installed version of go against minimum requirement.
59 @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
60 exit 0 ;\
61 elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
62 echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
63 exit 1; \
64 elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
65 echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
66 exit 1; \
67 fi