-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
91 lines (73 loc) · 3.16 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
GO := go
GOPATH := $(shell go env GOPATH)
GOPATH_BIN := $(GOPATH)/bin
GOLANGCI_LINT := $(GOPATH_BIN)/golangci-lint
SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
GOIMPORTS := $(GOPATH_BIN)/goimports
GO_PACKAGES = $(shell go list ./... | grep -v vendor)
PACKAGE_BASE := github.com/sdslabs/nymeria
DB_HOST = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'host:' | sed -n 's/.*host: *"\?\([^"]*\)"\?/\1/p')
DB_PORT = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'port:' | sed -n 's/.*port: *"\?\([^"]*\)"\?/\1/p')
DB_USER = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'user:' | sed -n 's/.*user: *"\?\([^"]*\)"\?/\1/p')
DB_PASS = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'password:' | sed -n 's/.*password: *"\?\([^"]*\)"\?/\1/p')
DB_NAME = $(shell awk '/db:/,/db_name:/' config.yaml | grep 'db_name:' | sed -n 's/.*db_name: *"\?\([^"]*\)"\?/\1/p')
UP_MIGRATION_FILE = db/migrations/000001_init_schema.up.sql
DOWN_MIGRATION_FILE = db/migrations/000001_init_schema.down.sql
.PHONY: help vendor build run dev lint format clean
help:
@echo "Nymeria make help"
@echo ""
@echo "vendor: Downloads the dependencies in the vendor folder"
@echo "build: Builds the binary of the server"
@echo "run: Runs the binary of the server"
@echo "dev: Combines build and run commands"
@echo "lint: Lints the code using vet and golangci-lint"
@echo "format: Formats the code using fmt and golangci-lint"
@echo "clean: Removes the vendor directory and binary"
vendor:
@${GO} mod tidy
@${GO} mod vendor
@echo "Vendor downloaded successfully"
build:
@${GO} build -o nymeria ./cmd/nymeria/main.go
@echo "Binary built successfully"
run:
@./nymeria
dev:
@$(GOPATH_BIN)/air -c .air.toml
install-golangci-lint:
@echo "=====> Installing golangci-lint..."
@curl -sSfL \
https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b $(GOPATH_BIN) v1.62.2
lint: install-golangci-lint
@$(GO) vet $(GO_PACKAGES)
@$(GOLANGCI_LINT) run -c golangci.yaml
@echo "Lint successful"
install-goimports:
@echo "=====> Installing formatter..."
@$(GO) install golang.org/x/tools/cmd/goimports@latest
format: install-goimports
@echo "=====> Formatting code..."
@$(GOIMPORTS) -l -w -local ${PACKAGE_BASE} $(SRC)
@echo "Format successful"
## verify: Run format and lint checks
verify: verify-format lint
## verify-format: Verify the format
verify-format: install-goimports
@echo "=====> Verifying format..."
$(if $(shell $(GOIMPORTS) -l -local ${PACKAGE_BASE} ${SRC}), @echo ERROR: Format verification failed! && $(GOIMPORTS) -l -local ${PACKAGE_BASE} ${SRC} && exit 1)
clean:
@rm -f nymeria
@rm -rf vendor/
@echo "Clean successful"
install-air:
@echo "Make sure your GOPATH and GOPATH_BIN is set"
@curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(GOPATH_BIN)
@echo "Air installed successfully"
apply-migration:
@echo "Applying migration..."
PGPASSWORD=$(DB_PASS) psql -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) -d $(DB_NAME) -f $(UP_MIGRATION_FILE)
rollback-migration:
@echo "Rolling back migration..."
PGPASSWORD=$(DB_PASS) psql -h $(DB_HOST) -p $(DB_PORT) -U $(DB_USER) -d $(DB_NAME) -f $(DOWN_MIGRATION_FILE)