-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
112 lines (92 loc) · 2.89 KB
/
Makefile
File metadata and controls
112 lines (92 loc) · 2.89 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
BUILD_PATH=tmp
GEN_PATH=internal/gen
PROTO_PATH=proto
MAIN_PACKAGE_PATH=./cmd/protoc-gen-sqlc
BINARY_NAME=protoc-gen-sqlc
LIBRARY_EXAMPLE_PATH=examples/library
LIBRARY_EXAMPLE_CONFIG=buf.gen.yaml
BUF_VERSION=v1.68.4
SQLC_VERSION=v1.31.1
GOLANGCILINT_VERSION=v2.11.4
PROTOC_GEN_GO_VERSION=v1.36.11
.PHONY: help
help:
@echo 'Build scripts for $(BINARY_NAME)'
@echo 'Usage:'
@sed -n 's/^##//p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /'
.PHONY: no-dirty
no-dirty:
git diff --exit-code
.PHONY: format
format:
go fmt ./...
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCILINT_VERSION) fmt ./...
.PHONY: tidy
tidy: format
go mod tidy -v
## audit: run quality control checks
.PHONY: audit
audit: tidy
go mod verify
go vet ./...
go test -v -race -failfast -buildvcs -vet=off ./...
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCILINT_VERSION) run ./...
go run github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION) lint
## test: run all tests
.PHONY: test
test:
go test -v -race -buildvcs ./...
## test/cover: run all tests and display coverage
.PHONY: test/cover
test/cover:
go test -v -race -buildvcs -coverprofile=$(BUILD_PATH)/coverage.out ./...
go tool cover -html=$(BUILD_PATH)/coverage.out
## build: build the executable
.PHONY: build
build: protoc-gen-go
go run github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION) generate --path $(PROTO_PATH)/sqlc
go build -o=$(BUILD_PATH)/$(BINARY_NAME) $(MAIN_PACKAGE_PATH)
## run: run the executable
.PHONY: run
run: build
$(BUILD_PATH)/$(BINARY_NAME)
## protoc: compile protocol buffers
.PHONY: protoc
protoc: build
go run github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION) generate \
--template $(LIBRARY_EXAMPLE_PATH)/$(LIBRARY_EXAMPLE_CONFIG) \
--path $(PROTO_PATH)/examples
protoc-gen-go:
go install google.golang.org/protobuf/cmd/protoc-gen-go@$(PROTOC_GEN_GO_VERSION)
## sqlc: generate idiomatic code from SQL files
.PHONY: sqlc
sqlc: protoc
cd $(LIBRARY_EXAMPLE_PATH) && \
go run github.com/sqlc-dev/sqlc/cmd/sqlc@$(SQLC_VERSION) generate
## exampledb/up: start PostgreSQL container used for the example
.PHONY: exampledb/up
exampledb/up:
docker compose -f $(LIBRARY_EXAMPLE_PATH)/compose.yml up -d
## exampledb/down: stop PostgreSQL container used for the example
.PHONY: exampledb/down
exampledb/down:
docker compose -f $(LIBRARY_EXAMPLE_PATH)/compose.yml down
## example/library: run library example
.PHONY: example/library
example/library: exampledb/up sqlc
cd $(LIBRARY_EXAMPLE_PATH) && go run main.go
## push: push changes to the remote Git repository
.PHONY: push
push: clean sqlc audit test/cover no-dirty
git push
## upgrade: upgrade Go dependencies
.PHONY: upgrade
upgrade:
go get -u -t ./...
go mod tidy -v
## clean: clean all generated artifacts
.PHONY: clean
clean: exampledb/down
rm -rf $(BUILD_PATH)
rm -rf $(LIBRARY_EXAMPLE_PATH)/$(GEN_PATH)