| iomodo | 838bd5c | 2021-03-21 15:37:03 +0400 | [diff] [blame] | 1 | GO ?= $(shell command -v go 2> /dev/null) |
| 2 | GO_TEST_FLAGS ?= -race |
| 3 | |
| 4 | export GO111MODULE=on |
| 5 | |
| 6 | MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1 |
| 7 | MINIMUM_SUPPORTED_GO_MINOR_VERSION = 14 |
| 8 | GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) |
| 9 | GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) |
| 10 | GO_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 | |
| 12 | BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)" |
| 13 | |
| 14 | ## Define the default target (make all) |
| 15 | .PHONY: default |
| 16 | default: all |
| 17 | |
| 18 | ## Checks the code style, tests, runs the code. |
| 19 | .PHONY: all |
| 20 | all: check-style test run |
| 21 | |
| 22 | ## Runs eslint and golangci-lint |
| 23 | .PHONY: check-style |
| 24 | check-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 |
| 35 | test: |
| 36 | @echo Running unit tests |
| 37 | $(GO) test -v $(GO_TEST_FLAGS) ./... |
| 38 | |
| 39 | ## Creates a coverage report |
| 40 | .PHONY: coverage |
| 41 | coverage: |
| 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 |
| 47 | clean: |
| 48 | rm -fr coverage.txt |
| 49 | rm -fr server.log |
| 50 | |
| 51 | .PHONY: run |
| 52 | run: validate-go-version |
| 53 | @echo Running Knowledge Graph services |
| 54 | |
| 55 | $(GO) run ./cmd/ |
| 56 | |
| 57 | .PHONY: validate-go-version |
| 58 | validate-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 |