-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
94 lines (75 loc) · 1.88 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
# Project directory structure
PROJECT_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
# Artifacts
TARGET_DIR = target
# Go environment
GOVERSION := $(shell go version | awk '{print $$3}')
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
#
# User commands
#
DC=docker compose -f development/docker-compose.yml
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: env
env: ## Print current development environment
@echo "PROJECT_PATH:\t${PROJECT_PATH}"
@echo "GOVERSION:\t${GOVERSION}"
@echo "GOOS:\t\t${GOOS}"
@echo "GOARCH:\t\t${GOARCH}"
.PHONY: dev
dev: setup ## Run development server
@go run ./cmd
.PHONY: setup
setup: deps ## Setup development dependencies in background
.PHONY: generate
generate: _generate
##@ Build
.PHONY: build
build: deps _build ## Build project
.PHONY: deps
deps: ## Sync project dependencies
@go mod download
@go mod tidy
.PHONY: lint
lint: ## Run linter and formatter
@echo Running lint...
@if command -v golangci-lint >/dev/null 2>&1; then \
make _lint; \
else \
$(DC) run --rm lint; \
fi
@echo Done
.PHONY: test
test: ## Run tests
make _test
##@ Cleanup
.PHONY: down
down: ## Clean up local development dependencies
@$(DC) down
.PHONY: clean
clean: ## Clean up all local state
@rm -rf ${TARGET_DIR}
@$(DC) down -v
#
# Internal commands for ci
#
.PHONY: _generate
_generate: _generate-docs
.PHONY: _generate-docs
_generate-docs:
@echo Generating docs...
@swag init -d cmd,api/public/http/route -o api/public/http/docs
@swag fmt
.PHONY: _build
_build:
@go build -o ${TARGET_DIR}/app ./cmd
.PHONY: _test
_test:
@go test -count=1 ./...
.PHONY: _lint
_lint:
@golangci-lint run