-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
123 lines (96 loc) · 3.44 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# =============================================================================
# Project Configuration
# =============================================================================
# Project metadata
PROJECT_NAME := geoblock
DESCRIPTION := A simple IP-based geoblocking service
# Directories
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
DIST_DIR := $(ROOT_DIR)/dist
# Colors
BLUE := \033[34m
GREEN := \033[32m
YELLOW := \033[33m
RED := \033[31m
MAGENTA := \033[35m
CYAN := \033[36m
WHITE := \033[37m
BOLD := \033[1m
RESET := \033[0m
# =============================================================================
# @Linters
# =============================================================================
.PHONY: lint
lint: lint-lines lint-revive lint-sec lint-vet ## Run all linters
.PHONY: lint-lines
lint-lines: ## Lint lines length
golines -w -m 79 --base-formatter=gofumpt .
.PHONY: lint-revive
lint-revive: ## Run revive linter
revive -config revive.toml ./...
.PHONY: lint-sec
lint-sec: ## Run gosec linter
gosec --exclude-dir=internal/tools ./...
.PHONY: lint-vet
lint-vet: ## Run go-vet linter
go vet ./...
# =============================================================================
# @Dependencies
# =============================================================================
.PHONY: deps-tidy
deps-tidy: ## Tidy up dependencies
go mod tidy
.PHONY: deps-update
deps-update: ## Update dependencies
go get -u ./...
.PHONY: deps-tools
deps-tools: ## Install development dependencies
go install github.com/boumenot/gocover-cobertura@latest
go install github.com/mgechev/revive@latest
go install github.com/securego/gosec/v2/cmd/gosec@latest
go install github.com/segmentio/golines@latest
go install mvdan.cc/gofumpt@latest
# =============================================================================
# Directory Creation
# =============================================================================
$(DIST_DIR):
mkdir -p $@
# =============================================================================
# @Build
# =============================================================================
.PHONY: run
run: ## Run the main program
go run ./cmd/geoblock/
.PHONY: build
build: $(DIST_DIR) ## Build the binary
go build -ldflags="-s -w" -o $(DIST_DIR)/geoblock ./cmd/geoblock/
.PHONY: docker
docker: ## Build docker image
docker build -t geoblock .
# =============================================================================
# @Tests
# =============================================================================
.PHONY: test
test: test-unit test-e2e ## Run all tests
.PHONY: test-unit
test-unit: ## Run unit tests
go test -coverprofile=coverage.out ./...
.PHONY: test-e2e
test-e2e: ## Run end-to-end tests
docker build -f tests/Dockerfile -t geoblock-tests .
docker run --rm geoblock-tests
.PHONY: test-coverage
test-coverage: test-unit ## Generate coverage report
gocover-cobertura < coverage.out > coverage.xml
# =============================================================================
# @Help
# =============================================================================
.PHONY: help
help: ## Display this help message
@echo "$(CYAN)$(BOLD)$(PROJECT_NAME) - $(DESCRIPTION)$(RESET)"
@awk 'BEGIN { FS = ":.*?##" } \
/^[a-zA-Z0-9._-]+:.*?##/ { printf " $(CYAN)%-15s$(RESET) %s\n", $$1, $$2 } \
/^# @/ { printf "\n$(MAGENTA)%s$(RESET)\n\n", substr($$0, 4) }' \
$(MAKEFILE_LIST)
@echo
.DEFAULT_GOAL := help