-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
139 lines (118 loc) · 3.82 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
131
132
133
134
135
136
137
138
139
include .env
MAIN_PACKAGE := ./cmd/api/main.go
BINARY_NAME := neoshare
DB_MIGRATION_DIR := ./internal/database/migrations
DB_CONN_STRING := "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}?sslmode=disable"
# ==================================================================================== #
# DEVELOPMENT
# ==================================================================================== #
## build: Build the production code
.PHONY: build
build:
@echo "Building binary..."
@templ generate
@bun run build
@CGO_ENABLED=0 go build -o bin/${BINARY_NAME} ${MAIN_PACKAGE}
## dev: Run the code development environment
.PHONY: dev
dev:
@echo "Running development environment..."
@go run ${MAIN_PACKAGE}
## watch: Run the application with reloading on file changes
.PHONY: watch
watch:
@if command -v air > /dev/null; then \
air; \
echo "Watching...";\
else \
read -p "Go's 'air' is not installed on your machine. Do you want to install it? [Y/n] " choice; \
if [ "$$choice" != "n" ] && [ "$$choice" != "N" ]; then \
go install github.com/air-verse/air@latest; \
air; \
echo "Watching...";\
else \
echo "You chose not to install air. Exiting..."; \
exit 1; \
fi; \
fi
## gen-repo: Generate the repository with sql queries provided
.PHONY: gen-repo
gen-repo:
@sqlc generate -f ./internal/database/sqlc.yaml
@echo "Repository generated..."
## update: Updates the packages and tidy the modfile
.PHONY: update
update:
@go get -u ./...
@go mod tidy -v
# ==================================================================================== #
# Database
# ==================================================================================== #
## db-up: Create DB container
.PHONY: db-up
db-up:
@if docker compose up -d psql 2>/dev/null; then \
: ; \
else \
echo "Falling back to Docker Compose V1"; \
docker-compose up -d psql; \
fi
@echo "DB container is up and running..."
## db-down: Shutdown DB container
.PHONY: db-down
db-down:
@if docker compose down psql 2>/dev/null; then \
: ; \
else \
echo "Falling back to Docker Compose V1"; \
docker-compose down psql; \
fi
@echo "DB container is down..."
## migrate-up: Migrate to up the table schema
.PHONY: migrate-up
migrate-up:
@GOOSE_DRIVER=postgres GOOSE_MIGRATION_DIR=${DB_MIGRATION_DIR} GOOSE_DBSTRING=${DB_CONN_STRING} goose up
## migrate-down: Migrate to down the table schema
.PHONY: migrate-down
migrate-down:
@GOOSE_DRIVER=postgres GOOSE_MIGRATION_DIR=${DB_MIGRATION_DIR} GOOSE_DBSTRING=${DB_CONN_STRING} goose down
## migrate-status: Displays about the migration status for the current DB
.PHONY: migrate-status
migrate-status:
@GOOSE_DRIVER=postgres GOOSE_MIGRATION_DIR=${DB_MIGRATION_DIR} GOOSE_DBSTRING=${DB_CONN_STRING} goose status
## sqlc-gen: Generate the sqlc queries
.PHONY: sqlc-gen
sqlc-gen:
@sqlc generate -f ./internal/database/sqlc.yaml
# ==================================================================================== #
# QUALITY CONTROL
# ==================================================================================== #
## tidy: Format code and tidy modfile
.PHONY: tidy
tidy:
@echo "Tidying up..."
@go fmt ./...
@go mod tidy -v
## lint: Run linter
.PHONY: lint
lint:
@echo "Linting..."
@golangci-lint run -v
## test: Test the application
.PHONY: test
test:
@echo "Testing..."
@go test ./... -v
# ==================================================================================== #
# HELPERS
# ==================================================================================== #
## clean: Clean the binary and cache files
.PHONY: clean
clean:
@echo "Cleaning..."
@rm -rf bin/ .parcel-cache/ node_modules/ static/
## help: Print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'