-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
130 lines (107 loc) · 3.81 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
124
125
126
127
128
129
130
OS := $(shell uname -s)
FRONTEND_DIST_DIR := frontend/dist
FRONTEND_DIST_URL := https://github.com/oj-lab/frontend/releases/download/v0.1.0/dist.zip
ICPC_PROBLEM_PACKAGES_DIR := problem-packages/icpc
ICPC_PROBLEM_PACKAGES_URL := https://github.com/oj-lab/problem-packages/releases/download/v0.0.1/icpc_problem.zip
.PHONY: help
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " build - Build the application, swagger document will be generated"
@echo " run - Run the application"
@echo " clean - Clean the build"
@echo " check - Run go vet"
@echo " test - Run tests, database will be setup"
@echo " gen-swagger - Generate swagger document"
@echo " setup-dependencies - Setup the dependencies docker image"
@echo " unset-dependencies - Unset the dependencies docker image"
@echo " get-front - Get the frontend files"
@echo " update-front - Update the frontend files"
@echo " get-problem-packages - Get the problem packages"
@echo " update-problem-packages - Update the problem packages"
.PHONY: build
build: gen-swagger gen-proto
@echo "Building on $(OS)"
go mod tidy
go build -o bin/ ./cmd/...
.PHONY: run
run: build
./bin/web_server
.PHONY: clean
clean:
rm -rf bin
rm -rf cmd/web_server/swaggo_gen
.PHONY: gen-swagger
gen-swagger: install-swaggo
swag fmt -d cmd/web_server
swag init -d cmd/web_server,models -ot go -o cmd/web_server/swaggo_gen
# Deprecated
# But still needed to pass the build
.PHONY: gen-proto
gen-proto: install-proto
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative \
proto/*.proto
# Targets for development
.PHONY: unset-dependencies
unset-dependencies:
docker compose stop postgres redis minio
docker compose rm -f postgres redis minio
.PHONY: unset-data
unset-data: build
./bin/clean
.PHONY: setup-dependencies
setup-dependencies: build get-front get-problem-packages
@if [ "$(shell docker ps -f status=running | grep -E "postgres|redis|minio" | wc -l)" -eq 4 ]; then \
echo "Containers already up"; \
./bin/clean; \
else \
docker compose up -d postgres redis minio; \
@echo "Wait 10 seconds for db setup"; \
sleep 10s; \
fi
./bin/init;
.PHONY: get-front
get-front:
./scripts/download_and_unzip.sh $(FRONTEND_DIST_DIR) $(FRONTEND_DIST_URL) \
OVERRIDE=false
.PHONY: update-front
update-front:
./scripts/download_and_unzip.sh $(FRONTEND_DIST_DIR) $(FRONTEND_DIST_URL) \
OVERRIDE=true
.PHONY: get-problem-packages
get-problem-packages:
./scripts/download_and_unzip.sh $(ICPC_PROBLEM_PACKAGES_DIR) $(ICPC_PROBLEM_PACKAGES_URL) \
OVERRIDE=false
.PHONY: update-problem-packages
update-problem-packages:
./scripts/download_and_unzip.sh $(ICPC_PROBLEM_PACKAGES_DIR) $(ICPC_PROBLEM_PACKAGES_URL) \
OVERRIDE=true
.PHONY: check
check: gen-proto install-cilint
golangci-lint run
.PHONY: test
test: build gen-swagger setup-dependencies
go test -race -covermode=atomic -coverprofile=coverage.out -cover -v -count=1 \
./models/... ./modules/... ./services/...
# Dependent targets
.PHONY: install-swaggo
install-swaggo:
go install github.com/swaggo/swag/cmd/swag@latest
# See more: https://golangci-lint.run/welcome/install/#local-installation
.PHONY: install-cilint
install-cilint:
@if [ -z $(shell which golangci-lint) ]; then \
echo "Installing golangci-lint"; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin latest; \
fi
# Deprecated
# But still needed to pass the build
.PHONY: install-proto
install-proto:
@# Referencing https://grpc.io/docs/protoc-installation/
@./scripts/install_protoc.sh
@# Track https://grpc.io/docs/languages/go/quickstart/ for update
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]