-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
60 lines (51 loc) · 1.94 KB
/
Makefile
File metadata and controls
60 lines (51 loc) · 1.94 KB
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
PROJECT := aichat-proxy
MODULE := $(shell go list -m)
VERSION ?= $(shell git describe --exact-match --tags HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || date '+%Y%m%d-%H%M%S')
.PHONY: tidy
tidy: ##@ Tidy go.mod and go.sum.
@go mod tidy
.PHONY: test
test: tidy ##@ Test all packages. (Recommended: https://github.com/gotestyourself/gotestsum)
@if command -v gotestsum >/dev/null 2>&1; then \
gotestsum --format pkgname --format-icons text -- -race -count 1 -failfast -v ./...; \
else \
go test -race -count 1 -failfast -v ./...; \
fi
.PHONY: lint
lint: tidy ##@ Lint all packages.
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run --timeout 5m; \
echo "done."; \
else \
echo "golangci-lint is not installed. Please install it from https://github.com/golangci/golangci-lint"; \
exit 1; \
fi
.PHONY: bin
bin: tidy ##@ Build the application.
@CGO_ENABLED=0 go build -tags 'release' -ldflags '-s -w' -o ./bin/$(PROJECT) $(MODULE)/server
.PHONY: bin-linux
bin-linux: tidy ##@ Build the application for linux.
@GOOS=linux CGO_ENABLED=0 go build -tags 'release' -ldflags '-s -w' -o ./bin/$(PROJECT)-linux $(MODULE)/server
.PHONY: run
run: bin ##@ Run the application.
@./bin/$(PROJECT) $(ARGS)
.PHONY: swag
swag: ##@ Generate swagger files.
@go run github.com/swaggo/swag/cmd/swag@latest fmt -d server -g api/routes.go
@go run github.com/swaggo/swag/cmd/swag@latest init -o server/docs -ot go,yaml -d server -g api/routes.go
.PHONY: help
help: ##@ (Default) Show help.
@printf "\nUsage: make <command>\n"
@grep -F -h "##@" $(MAKEFILE_LIST) | grep -F -v grep -F | sed -e 's/\\$$//' | awk 'BEGIN {FS = ":*[[:space:]]*##@[[:space:]]*"}; \
{ \
if($$2 == "") \
pass; \
else if($$0 ~ /^#/) \
printf "\n%s\n", $$2; \
else if($$1 == "") \
printf " %-20s%s\n", "", $$2; \
else \
printf "\n \033[34m%-20s\033[0m %s\n", $$1, $$2; \
}'
@printf "\n"
.DEFAULT_GOAL := help