-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
90 lines (73 loc) · 2.1 KB
/
Makefile
File metadata and controls
90 lines (73 loc) · 2.1 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
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
default: help
PROJECTNAME=$(shell basename "$(PWD)")
CLI_MAIN_FOLDER=./cmd/server
BIN_FOLDER=bin
BIN_NAME=${PROJECTNAME}
MIGRATIONS_DIR=./migrations
MIGRATIONS_ENV=./migrations/.env
## setup: install all build dependencies for ci
setup: mod-download
## compile: compiles project in current system
compile: clean generate fmt vet test build build-frontend
## watch: format, test, build and run the project
watch:
@echo " > Watching go files..."
@if !type "entr" > /dev/null 2>&1; then \
echo "Please install entr: http://eradman.com/entrproject/"; \
else \
make migrate; \
find . -path ./.database -prune -or -type f -name "*.go" -print \
| entr -nr make clean generate fmt vet build run; \
fi
## migrate: migrate the database to the lastest version
migrate:
@echo " > Migrating database..."
@if !type "goose" > /dev/null 2>&1; then \
echo " > goose not found, installing..."; \
go install github.com/pressly/goose/v3/cmd/goose@latest; \
fi
@echo " > Running migrations"
@goose -env ${MIGRATIONS_ENV} -dir ${MIGRATIONS_DIR} up
## run: build project and run it
run:
@echo " > Running binary"
./${BIN_FOLDER}/${BIN_NAME}
clean:
@echo " > Cleaning build cache"
@-rm -rf ${BIN_FOLDER}/amd64 ${BIN_FOLDER}/${BIN_NAME} ${BIN_FOLDER}/dist \
&& go clean ./...
build:
@echo " > Building binary"
@mkdir -p ${BIN_FOLDER}
@go build \
-o ${BIN_FOLDER}/${BIN_NAME} \
"${CLI_MAIN_FOLDER}"
build-frontend:
@echo " > Building frontend"
@npm --prefix frontend run build
@mv frontend/dist ${BIN_FOLDER}
fmt:
@echo " > Formatting code"
@go fmt ./...
generate:
@echo " > Go generate"
@if !type "stringer" > /dev/null 2>&1; then \
go install golang.org/x/tools/cmd/stringer@latest; \
fi
@go generate ./...
mod-download:
@echo " > Download dependencies..."
@go mod download && go mod tidy
test:
@echo " > Executing unit tests"
@go test -v -timeout 60s -race ./...
vet:
@echo " > Checking code with vet"
@go vet ./...
.PHONY: help
all: help
help: Makefile
@echo "Choose a command to run in "$(PROJECTNAME)":"
@echo
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
@echo