-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
60 lines (47 loc) · 1.63 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
MAKEFLAGS += --warn-undefined-variables
NC :=\033[0m
BLUE :=\033[36m
GREEN :=\033[0;32m
APP := cataloger
BINARY ?= $(APP)
# BINARY ?= $(APP)-$(RELEASE)_$(GOARCH)_$(GOOS)
RELEASE ?= $(shell git rev-parse --short HEAD)
COMMIT := $(shell git rev-parse HEAD)
DATE ?= $(shell date '+%Y-%m-%d_%H:%M:%S')
BUILD_NUM ?=
BIN_DIR := bin
TESTS_DIR := tests
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
default: help
help: ## Display available make commands
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "$(BLUE)%-12s$(NC) %s\n", $$1, $$2}'
all: deps prep lint tests build ## All included
@echo "$(GREEN)All done!$(NC)"
deps: ## Checks all required dependencies to be installed
@echo "$(BLUE)• Checking dependencies$(NC)"
@which go
@which golangci-lint
tests: ## Run all tests
@echo "$(BLUE)• Running unit tests$(NC)"
go test -race -coverprofile=$(TESTS_DIR)/coverage.out ./...
.PHONY: tests
lint: ## Applies linter
@echo "$(BLUE)• Running linter$(NC)"
golangci-lint run -c ./.golangci.yml --timeout 3m ./...
prep: ## Performs all required build preparations.
@mkdir -p tests
@mkdir -p $(BIN_DIR)
clean: ## Clean before build
@echo "$(BLUE)• Clean before build$(NC)"
go clean
rm -f $(BIN_DIR)/$(BINARY)
build: clean ## Build binary
@echo "$(BLUE)• Building binary$(NC)"
@GOOS=$(GOOS) GOARCH=$(GOARCH) go build \
-ldflags "-X '$(APP)/info.Release=$(RELEASE)' \
-X '$(APP)/info.BuildTime=$(DATE)' \
-X '$(APP)/info.CommitHash=$(COMMIT)' \
-X '$(APP)/info.BuildNumber=$(BUILD_NUM)'"\
-o $(BIN_DIR)/$(BINARY)
@chmod +x $(BIN_DIR)/$(BINARY)