-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
143 lines (108 loc) · 3.2 KB
/
Copy pathMakefile
File metadata and controls
143 lines (108 loc) · 3.2 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
.PHONY: run dev build test test-unit test-integration lint fmt migrate-up migrate-down sqlc swagger docker-up docker-down docker-dev docker-dev-down docker-dev-logs seed seed-up clean rename install-tools install-air precommit install-hooks
APP_NAME := go-codebase
BUILD_DIR := bin
GOINSTALL = go install
GOLANGCI_LINT := $(shell command -v golangci-lint 2>/dev/null)
GOIMPORTS := $(shell command -v goimports 2>/dev/null)
GOOSE := $(shell command -v goose 2>/dev/null)
SQLC := $(shell command -v sqlc 2>/dev/null)
SWAG := $(shell command -v swag 2>/dev/null)
AIR := $(shell command -v air 2>/dev/null)
install-tools:
ifndef GOLANGCI_LINT
$(GOINSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint@latest
endif
ifndef GOIMPORTS
$(GOINSTALL) golang.org/x/tools/cmd/goimports@latest
endif
ifndef GOOSE
$(GOINSTALL) github.com/pressly/goose/v3/cmd/goose@latest
endif
ifndef SQLC
$(GOINSTALL) github.com/sqlc-dev/sqlc/cmd/sqlc@latest
endif
ifndef SWAG
$(GOINSTALL) github.com/swaggo/swag/cmd/swag@latest
endif
ifndef AIR
$(GOINSTALL) github.com/air-verse/air@latest
endif
run:
go run ./cmd/api
dev: install-tools
air
install-air:
ifndef AIR
$(GOINSTALL) github.com/air-verse/air@latest
endif
build:
go build -o $(BUILD_DIR)/$(APP_NAME) ./cmd/api
test:
go test -v -count=1 ./...
test-unit:
go test -v -count=1 $(shell go list ./... | grep -v /tests/)
test-integration:
go test -v -count=1 $(shell go list ./... | grep /tests/)
test-coverage:
go test -v -count=1 -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
lint: install-tools
golangci-lint run ./...
fmt: install-tools
go fmt ./...
goimports -w .
migrate-up: install-tools
goose -dir migrations up
migrate-down: install-tools
goose -dir migrations down
sqlc: install-tools
sqlc generate
swagger: install-tools
swag init -g cmd/api/swagger.go -o docs --parseDependency --parseInternal
precommit: install-tools mod-tidy
@echo "=== Checking formatting ==="
@if [ -n "$$(go fmt ./...)" ]; then \
echo "ERROR: Files not formatted. Run 'make fmt' and commit again."; \
exit 1; \
fi
@echo "=== Linting ==="
golangci-lint run ./...
@echo "=== Building ==="
go build ./...
@echo "=== Testing ==="
go test -count=1 ./...
@echo "=== All checks passed ==="
install-hooks:
@echo "Installing pre-commit hook..."
@printf '#!/bin/sh\nmake -C "$(CURDIR)" precommit\n' > .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "Pre-commit hook installed."
docker-up:
docker compose up -d
docker-down:
docker compose down
docker-build:
docker compose build
docker-prod-up:
docker compose -f docker-compose.prod.yml up -d
docker-prod-down:
docker compose -f docker-compose.prod.yml down
docker-prod-migrate:
docker compose -f docker-compose.prod.yml --profile migrate run --rm migrate
docker-dev:
docker compose -f docker-compose.dev.yml up -d --build
docker-dev-down:
docker compose -f docker-compose.dev.yml down
docker-dev-logs:
docker compose -f docker-compose.dev.yml logs -f api
seed:
go run ./cmd/seed
seed-up: migrate-up seed
@echo "Migration and seed complete"
clean:
rm -rf $(BUILD_DIR) coverage.out coverage.html
mod-tidy:
go mod tidy
rename:
./scripts/rename-module.sh $(MODULE)
.DEFAULT_GOAL := run