Makefile
1.75 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
ifneq (,$(wildcard .env))
include .env
export
endif
BINDIR := bin
APPS := $(notdir $(wildcard cmd/*))
BUILD_TARGETS := $(filter-out build clean, $(MAKECMDGOALS))
.PHONY: build clean default
default: build
build:
@mkdir -p $(BINDIR)
@if [ -z "$(strip $(BUILD_TARGETS))" ]; then \
echo "No specific app provided. Building all apps..."; \
for app in $(APPS); do \
echo "Building $$app..."; \
go build -o $(BINDIR)/$$app ./cmd/$$app; \
done; \
else \
for arg in $(BUILD_TARGETS); do \
if echo $$arg | grep -q -- '-$$'; then \
prefix=$${arg%-}; \
echo "Building all apps starting with '$$prefix'..."; \
for app in $(APPS); do \
case "$$app" in \
$$prefix*) \
echo "Building $$app..."; \
go build -o $(BINDIR)/$$app ./cmd/$$app;; \
esac; \
done; \
else \
echo "Building $$arg..."; \
go build -o $(BINDIR)/$$arg ./cmd/$$arg; \
fi; \
done; \
fi
clean:
@echo "Cleaning up binaries..."
@rm -rf $(BINDIR)
codecheck:
@echo "checking code. Running vet and fmt"
@go vet ./...
@go fmt ./...
test:
@echo "Running test"
@go test ./...
migrate-postgres:
@if [ -z "$(DATABASE_URL)" ]; then \
echo "Error: DATABASE_URL is not set. Please set it in .env or your environment."; \
exit 1; \
fi; \
echo "Running database migrations with goose using driver $$driver..."; \
goose -dir migration/postgres postgres "$(DATABASE_URL)" up
migrate-postgres-status:
@if [ -z "$(DATABASE_URL)" ]; then \
echo "Error: DATABASE_URL is not set. Please set it in .env or your environment."; \
exit 1; \
fi; \
echo "Running migration status with goose using driver $$driver..."; \
goose -dir migration/postgres postgres "$(DATABASE_URL)" status
%:
@: